首页 > web前端 > js教程 > 正文

jquery实现预览提交的表单代码分享_jquery

php中文网
发布: 2016-05-16 16:47:27
原创
2130人浏览过

预览表单,查看后确认提交或者返回重填

jquery实现预览提交的表单代码分享_jquery

XML/HTML Code

MindShow
MindShow

MindShow官网 | AI生成PPT,快速演示你的想法

MindShow 1492
查看详情 MindShow
复制代码 代码如下:

   
 
   
 
    Registeration 
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
   
 
   
 
   
Gender :  
     
     
   
 
   
 
   
 



JavaScript Code

复制代码 代码如下:

<script> <BR>$(document).ready(function() { <BR> $('#myform').previewForm(); <BR>}); <BR></script>

previewForm.js

复制代码 代码如下:

(function($){

 $.fn.previewForm = function(options){
  var form_settings = $.extend({
   identifier         : 'label',
   show_password        : true,
   extratext    : 'Do You Want To submit',
   yes  : 'yes',
   no  : 'no',
   title  : 'Please preview'   
  }, options);

   var dia_log; 
   var renderBUTTON;
   var this_frm;
   this_frm = $(this);

 $(this).submit(function (){

 if($('#pfomdata').length){
      return true;
     }

  
  dia_log="";
  var needle_cnfrm;

  if(this.id.length > 0){ needle_cnfrm = '#'+this.id+' label'; }
  else  { needle_cnfrm = '.'+$(this).attr('class')+' label'; }

 $(needle_cnfrm).each(function(i,val) {
  if($(this).text().length >2){

 what_t= $('#'+$(this).attr('for')) ;

 switch(what_t.prop('type')){
 case 'password':
 if(!form_settings.show_password)
  dia_log +=$(this).text() + " your selected password
";
 else
  dia_log +=$(this).text() +what_t.val()+"
";
  break;
 case 'select-one':
 dia_log +=$(this).text()  +$('#'+$(this).attr('for')+' option:selected').text()+"
";
  break;
 case 'radio':
 if( what_t.is(':checked'))
 dia_log +=$(this).text() +' '+what_t.val()+"
";
  break;
 case 'checkbox':
 if( what_t.is(':checked'))
 dia_log +=$(this).text() +' '+what_t.val()+"
";
  break;
 case 'undefined':
  break;
 default:
 dia_log +=$(this).text() +what_t.val()+"
";
 break;

 }
 }
  });
  dia_log = dia_log.replace('undefined', '');

  
  renderBUTTON="";
  renderBUTTON += ''+form_settings.yes+'';
  renderBUTTON += ''+form_settings.no+'';

  var renderTemplate = [
   '

',
   '
',
   '

',form_settings.title,'

',
   '

',dia_log,'

',
   '

',form_settings.extratext,'

',
   '
',
   renderBUTTON,
   '
'
  ].join('');

  $(renderTemplate).hide().appendTo('body').fadeIn();

 $(".form_yes") .click(function(){
   var input = $("").attr("type", "hidden").attr("id", "pfomdata").val("true");
    this_frm.append($(input));
    this_frm.submit();
   });

 $(".form_no") .click(function(){
    $('#previewOverlay').fadeOut(function(){
    $(this).remove();
     });
   });

 return false;

  });
 }

})(jQuery);

previewForm.css

复制代码 代码如下:

#previewOverlay{
 width:100%;
 height:100%;
 position:fixed;
 top:0;
 left:0;
 background:url('ie.png');
 background: -moz-linear-gradient(rgba(11,11,11,0.1), rgba(11,11,11,0.6)) repeat-x rgba(11,11,11,0.2);
 background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(11,11,11,0.1)), to(rgba(11,11,11,0.6))) repeat-x rgba(11,11,11,0.2);
 z-index:100000;
}

#previewBox{
 background:url('body_bg.jpg') repeat-x left bottom #e5e5e5;
 width:460px;
 position:fixed;
 left:50%;
 top:50%;
 margin:-130px 0 0 -230px;
 border: 1px solid rgba(33, 33, 33, 0.6);

 -moz-box-shadow: 0 0 2px rgba(255, 255, 255, 0.6) inset;
 -webkit-box-shadow: 0 0 2px rgba(255, 255, 255, 0.6) inset;
 box-shadow: 0 0 2px rgba(255, 255, 255, 0.6) inset;
}

#previewBox h1,
#previewBox p{
 font:26px/1 'Cuprum','Lucida Sans Unicode', 'Lucida Grande', sans-serif;
 background:url('header_bg.jpg') repeat-x left bottom #f5f5f5;
 padding: 18px 25px;
 text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.6);
 color:#666;
}

#previewBox h1{
 letter-spacing:0.3px;
 color:#888;
}

#previewBox p{
 background:none;
 font-size:16px;
 line-height:1.4;
 padding-top: 7px;
}

#previewButtons{
 padding:15px 0 25px;
 text-align:center;
}

#previewBox .button{
 display:inline-block;
 background:url('buttons.png') no-repeat;
 color:white;
 position:relative;
 height: 33px;

 font:17px/33px 'Cuprum','Lucida Sans Unicode', 'Lucida Grande', sans-serif;

 margin-right: 15px;
 padding: 0 35px 0 40px;
 text-decoration:none;
 border:none;
}

#previewBox .button:last-child{ margin-right:0;}

#previewBox .button span{
 position:absolute;
 top:0;
 right:-5px;
 background:url('buttons.png') no-repeat;
 width:5px;
 height:33px
}

#previewBox .form_yes{    background-position:left top;text-shadow:1px 1px 0 #5889a2;}
#previewBox .form_yes span{   background-position:-195px 0;}
#previewBox .form_yes:hover{  background-position:left bottom;}
#previewBox .form_yes:hover span{ background-position:-195px bottom;}

#previewBox .form_no{    background-position:-200px top;text-shadow:1px 1px 0 #707070;}
#previewBox .form_no span{   background-position:-395px 0;}
#previewBox .form_no:hover{  background-position:-200px bottom;}
#previewBox .form_no:hover span{ background-position:-395px bottom;}

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号