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

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

XML/HTML Code

代码如下:

<form class="mform" id="myform" method="POST" id="myform" action=""> 
    <fieldset> 
    <legend>Registeration</legend> 
    <table cellspacing="0"> 
    <tbody> 
    <tr> 
    <td><label for="u_name"> Username :</label></td> 
    <td><input type="text" name="uname" id="u_name"> 
    <td> 
    </tr> 
    <tr> 
    <td><label for="u_pwd"> Password :</label></td> 
    <td><input type="password" name="uname" id="u_pwd"></td> 
    </tr> 
    <tr> 
    <td><label for="u_mail"> Email :</label></td> 
    <td><input type="email" name="uname" id="u_mail"></td> 
    </tr> 
    <tr> 
    <td><label for="u_country"> Country :</label></td> 
    <td><select name="Country" id="u_country"> 
    <option value="" selected="selected">Select Country</option> 
    <option value="United States">United States</option> 
    <option value="United Kingdom">United Kingdom</option> 
    <option value="China">China</option> 
    </select></td> 
    </tr> 
    <tr> 
    <td><span> Gender :</span></td> 
    <td><input type="radio" name="gender" id="male" value="male"> 
    <label for="male"> Male</label> 
    <input type="radio" name="gender" id="female"  value="female"> 
    <label for="female"> Female </label></td> 
    </tr> 
    <tr> 
    <td><label for="subscribe"> Subscribe Us : </label></td> 
    <td><input type="checkbox" id="subscribe" name="subscribe" value="yes"></td> 
    </tr> 
    <tr> 
    <td></td> 
    <td><input type="submit" value="submit"></td> 
    </tr> 
    </tbody> 
    </table> 
    </fieldset> 
    </form> 
<script src="../../js/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="previewForm/previewForm.css" />
<script src="previewForm/previewForm.js"></script>

JavaScript Code

代码如下:

<script> 
$(document).ready(function() { 
    $('#myform').previewForm(); 
}); 
</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<br/>";
 else
  dia_log +=$(this).text() +what_t.val()+"<br/>";
  break;
 case 'select-one':
 dia_log +=$(this).text()  +$('#'+$(this).attr('for')+' option:selected').text()+"<br/>";
  break;
 case 'radio':
 if( what_t.is(':checked'))
 dia_log +=$(this).text() +' '+what_t.val()+"<br/>";
  break;
 case 'checkbox':
 if( what_t.is(':checked'))
 dia_log +=$(this).text() +' '+what_t.val()+"<br/>";
  break;
 case 'undefined':
  break;
 default:
 dia_log +=$(this).text() +what_t.val()+"<br/>";
 break;

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

renderBUTTON="";
  renderBUTTON += '<a href="javascript:void(0);" class="button form_yes">'+form_settings.yes+'<span></span></a>';
  renderBUTTON += '<a href="javascript:void(0);" class="button form_no">'+form_settings.no+'<span></span></a>';

var renderTemplate = [
   '<div id="previewOverlay">',
   '<div id="previewBox">',
   '<h1>',form_settings.title,'</h1>',
   '<p>',dia_log,'</p>',
   '<p>',form_settings.extratext,'</p>',
   '<div id="previewButtons">',
   renderBUTTON,
   '</div></div></div>'
  ].join('');

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

$(".form_yes") .click(function(){
   var input = $("<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;}

(0)

相关推荐

  • Jquery图片延迟加载插件jquery.lazyload.js的使用方法

    最新版的jquery.lazyload.js已不再是伪的延迟加载了 一.请按照基本使用方法说明设置 复制代码 代码如下: //载入JavaScript 文件<script src="jquery.js" type="text/javascript"></script><script src="jquery.lazyload.js" type="text/javascript"></sc

  • jQuery基于当前元素进行下一步的遍历

    如果我们已经通过jQuery方法选中了一组元素,那么如何基于这些已经选中的元素进行下一步的遍历呢? 例如,我们通过 $('li:eq(1)') 选中了以下代码中的第二个li元素. 复制代码 代码如下: <ul> <li><a href="#">link</a></li> <li><a href="#">selected link</a></li> <li

  • jquery实现兼容浏览器的图片上传本地预览功能

    一.图片上传实现本地预览 由于上传图片功能,现在大多数都需要在本地实现预览,为了能够更好的让用户体验到效果,实现成品的证明,需要兼容好几种浏览器,所有通过各个例子整合了这个例子插件,兼容火狐.谷歌.ie8,其他的没有进行测试过 复制代码 代码如下: (function($){ jQuery.fn.extend({ uploadPreview: function(opts){ opts = jQuery.extend({ width: 0, height: 0, imgPreview: null,

  • jQuery实现鼠标经过图片预览大图效果

    jQuery:是一种客户端的技术,它的诞生的理由是:write less,do more(写更少的代码,做更多的事情). 因此,我们可以借助jQuery来实现一些很酷炫的效果,相比于javaScript来说,同样的效果,但是很简单的代码.jQuery中的核心知识点就是选择器的使用,选择器的内容我会在之后的博客中总结,希望大家去看下,学好了选择我器,相当于完全掌握了jQuery. 这篇博文是实现怎么通过jQuery实现我们在购物网站中常见的:当鼠标经过了图片数,图片会放大进行预览大图.接下来我就粘

  • jquery repeater 模仿 Google 展开页面预览子视图

    如果, 有不明白的问题, 请先阅读 30 分钟掌握无刷新 Repeater. 示例代码下载: http://zsharedcode.googlecode.com/files/JQueryElementDemo.rar 本文将详细的讲解 Repeater 控件中如何使用子视图, 目录如下: * 准备 * 定义子视图样本 * 切换子视图状态 * 定义子视图容器 示例图片: 准备 请参照 http://code.google.com/p/zsharedcode/wiki/JQueryElementRe

  • 基于jquery实现的上传图片及图片大小验证、图片预览效果代码

    jquery实现上传图片及图片大小验证.图片预览效果代码 上传图片验证 复制代码 代码如下: */ function submit_upload_picture(){ var file = $('file_c').value; if(!/.(gif|jpg|jpeg|png|gif|jpg|png)$/.test(file)){ alert("图片类型必须是.gif,jpeg,jpg,png中的一种") }else{ $('both_form').action="file!u

  • jQuery实现图片放大预览实现原理及代码

    对于一些比较小的图片,通过鼠标移动到图片上进行放大显示,原理很简单,就是将图片显示的尺寸变大后放在浏览器的一个指定位置,从而实现图片的放大预览.以下是代码: 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns=&q

  • Jquery的each里用return true或false代替break或continue

    复制代码 代码如下: function methodone(){ .... $.each(array,function(){ if(条件成立){ return true; } }); .... } 在一个function里有一个each,在each里某种条件 成立的话,就把这个function返回true或者false 但是在each代码块内不能使用break和continue,要实现break和continue的功能的话,要使用其它的方式 break----用return false; con

  • jquery预览图片实现鼠标放上去显示实际大小

    复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=&qu

  • jquery 表格排序、实时搜索表格内容(附图)

    复制代码 代码如下: <table class="table-sort"> <thead> <tr> <th class="table-sort">First Name</th> <th class="table-sort">Last Name</th> <th class="table-sort">Email</th>

  • jquery 图片上传按比例预览插件集合

    js部分是这样的: 复制代码 代码如下: //**********************图片上传预览插件************************ //作者:IDDQD(2009-07-01) //Email:iddqd5376@163.com //http://blog.sina.com.cn/iddqd //版本:1.0 //说明:图片上传预览插件 //上传的时候可以生成固定宽高范围内的等比例缩放图 //参数设置: //width 存放图片固定大小容器的宽 //height 存放图片

随机推荐