《202X年JQuery.validate在ie8下不支持的快速解决方法》由会员分享,可在线阅读,更多相关《202X年JQuery.validate在ie8下不支持的快速解决方法(3页珍藏版)》请在金锄头文库上搜索。
1、下面小编就为大家带来一篇JQuery.validate在ie8下不支持的快速解决方法。小编觉得挺不错的,现在分享给大家,也给大家做个参考一、在ie8下回有问题的代码1、JQuery.validate验证框架是通过页面form表单提交验证&t;input/>标签中输入是否符合自己的规则的& t;form id=cardTypeFrm >&n bsp; & lt;table width=100% cellspaci ng=0 cellpaddi ng=0 class=table_pzh>&n bsp; &n bsp; <tbod y& gt; &n bsp; &n bsp;
2、 &n bsp; &n bsp; &n bsp ;&n bsp;用户名:</th >type=textclass=pzh_ in put1密码:</th >type=text class=pzh_ in put1&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;th class=f14 tr pc1>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >&n bsp; &n bsp; &n bsp; &n bsp; &n bsp; <
3、;i nput id=userName n ame=userName />&n bsp; &n bsp; &n bsp; &n bsp; </td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;th class=f14 tr pc1>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >&n bsp; &n bsp; &n bsp; &n bsp; &n bsp; &l
4、t;i nput id=passWord n ame=passWord />&n bsp; &n bsp; &n bsp; &n bsp; </td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; & t;/tbody >&n bsp; & t;/table >&n bsp; <p class=pc2 un dis pl50 error pa style=paddi ng-left:118px;marg in-top:-10px; id=card_next_error>错误信息 </p>
5、;&n bsp; & lt;div class=m20 tc>&n bsp; &n bsp; <i nput type=submit id=submitCardNo class=defi ne_butt on reservation_1 value=登陆 ” />&n bsp; &n bsp; & It; in put type=butto n value=取消 ” class=close_butt on closePzh ml10 />&n bsp; </div></form >其中name属性和下面js中的rules中的属性一致2、js绑定v
6、alidate事件代码如下$(fun ctio n() &n bsp; &n bsp; &n bsp; in itCardTypeFrmValidate()&n bsp; &n bsp; &n bsp; )function in itCardTypeFrmValidate() &n bsp; $(#cardTypeFrm).validate(&n bsp; &n bsp; on keyup : false,&n bsp; &n bsp; on focusout : false,&n bsp; &n bsp; rules : &n bsp; &n bsp; &n bsp; userName :
7、required : true&n bsp; &n bsp; &n bsp; password : required : true&n bsp; &n bsp; ,&n bsp; &n bsp; messages : userName : required : 请输入用户名, passWord : required : 请输入密码 &n bsp; &n bsp; ,&n bsp; &n bsp; errorEleme nt : p&n bsp; );on keyup : false,表示键盘输入不验证,默认tru
8、eon focusout : false,表示输入框失去焦点不验证,默认true二、解决方案是,禁止页面的表单提交,实行js中绑定表单提交表单1、html代码不变& t;form id=cardTypeFrm >&n bsp; & lt;table width=100% cellspaci ng=0 cellpaddi ng=0 class=table_pzh>&n bsp; &n bsp; <tbod y& gt; &n bsp; &n bsp; &n bsp; &n bsp; &n bsp ;&n bsp; &n bsp; &n bsp; &n bsp; & lt;tr&
9、gt;用户名:</th >type=textclass=pzh_ in put1密码:</th >type=text class=pzh_ in put1&n bsp; &n bsp; &n bsp; &n bsp; & lt;th class=f14 tr pc1>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >&n bsp; &n bsp; &n bsp; &n bsp;&n bsp; <i nput id=userName n ame=userName />&n bsp; &n bsp; &n bsp; &
10、n bsp; </td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;th class=f14 tr pc1>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >&n bsp; &n bsp; &n bsp; &n bsp; &n bsp; <i nput id=passWord n ame=passWord />&n bsp; &n bsp; &n bsp;
11、&n bsp; </td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; & t;/tbody >&n bsp; & t;/table >&n bsp; <p class=pc2 un dis pl50 error pa style=paddi ng-left:118px;marg in-top:-10px; id=card_next_error>错误信息 </p>&n bsp; & lt;div class=m20 tc>&n bsp; &n bsp; <i nputtype=
12、submit id=submitCardNoclass=defi ne_butt onreservation_1 value=登陆 ” />&n bsp; &n bsp; & It; in put type=butto n value=取消 ” class=close_butt on closePzh ml10 />&n bsp; </div></form >2、js代码中加入绑定提交事件$(fun ctio n() &n bsp; &n bsp; &n bsp; in itCardTypeFrmValidate()
13、/ 优化代码&n bsp; &n bsp; &n bsp; $(#cardTypeFrm).submit(fu nction() &n bsp; &n bsp; &n bsp; &n bsp; if ($(#cardTypeFrm).valid() &n bsp; &n bsp; &n bsp; &n bsp; &n bsp; / 通过执行的动作&n bsp; &n bsp; &n bsp; &n bsp; return false;/ 永远禁止页面表单提交&n bsp; &n bsp; &n bsp; )&n bsp; )functio
14、n in itCardTypeFrmValidate() &n bsp; $(#cardTypeFrm).validate(&n bsp; &n bsp; on keyup : false,&n bsp; &n bsp; on focusout : false,&n bsp; &n bsp; rules : &n bsp; &n bsp; &n bsp; userName : required : true&n bsp; &n bsp; &n bsp; passWord : required : true&n bsp; &n bsp; ,&n bsp; &n bsp; messages : userName : required : 请输入用户名, passWord : required : 请输入密码 &n bsp; &n bsp; ,&n bsp; &n bsp; errorEleme nt : p&n bsp; );以上这篇JQuery.validate在ie8下不支持的快速解决方法就是小编分享给大家的全部内 容了,希望能给大家一个参考