JQuery.validate在ie8下不支持解决方案 - 浮叶
一、在ie8下回有问题的代码
1、JQuery.validate验证框架是通过页面form表单提交验证标签中输入是否符合自己的规则的


<span style="color: #008080;"> 1</span> <span style="color: #0000ff;"><span style="color: #800000;">form </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="cardTypeFrm"</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 2</span> <span style="color: #0000ff;"><span style="color: #800000;">table </span><span style="color: #ff0000;">width</span><span style="color: #0000ff;">="100%"</span><span style="color: #ff0000;"> cellspacing</span><span style="color: #0000ff;">="0"</span><span style="color: #ff0000;"> cellpadding</span><span style="color: #0000ff;">="0"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="table_pzh"</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 3</span> <span style="color: #0000ff;"><span style="color: #800000;">tbody</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 4</span> <span style="color: #0000ff;"><span style="color: #800000;">tr</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 5</span> <span style="color: #0000ff;"><span style="color: #800000;">th </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="f14 tr pc1"</span><span style="color: #0000ff;">></span>用户名:<span style="color: #0000ff;"></span><span style="color: #800000;">th</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 6</span> <span style="color: #0000ff;"><span style="color: #800000;">td</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 7</span> <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="pzh_input1"</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">="userName"</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">="userName"</span> <span style="color: #0000ff;">/></span> <span style="color: #008080;"> 8</span> <span style="color: #0000ff;"></span><span style="color: #800000;">td</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 9</span> <span style="color: #0000ff;"></span><span style="color: #800000;">tr</span><span style="color: #0000ff;">></span> <span style="color: #008080;">10</span> <span style="color: #0000ff;"><span style="color: #800000;">tr</span><span style="color: #0000ff;">></span> <span style="color: #008080;">11</span> <span style="color: #0000ff;"><span style="color: #800000;">th </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="f14 tr pc1"</span><span style="color: #0000ff;">></span>密码:<span style="color: #0000ff;"></span><span style="color: #800000;">th</span><span style="color: #0000ff;">></span> <span style="color: #008080;">12</span> <span style="color: #0000ff;"><span style="color: #800000;">td</span><span style="color: #0000ff;">></span> <span style="color: #008080;">13</span> <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="pzh_input1"</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">="passWord"</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">="passWord"</span> <span style="color: #0000ff;">/></span> <span style="color: #008080;">14</span> <span style="color: #0000ff;"></span><span style="color: #800000;">td</span><span style="color: #0000ff;">></span> <span style="color: #008080;">15</span> <span style="color: #0000ff;"></span><span style="color: #800000;">tr</span><span style="color: #0000ff;">></span> <span style="color: #008080;">16</span> <span style="color: #0000ff;"></span><span style="color: #800000;">tbody</span><span style="color: #0000ff;">></span> <span style="color: #008080;">17</span> <span style="color: #0000ff;"></span><span style="color: #800000;">table</span><span style="color: #0000ff;">></span> <span style="color: #008080;">18</span> <span style="color: #0000ff;"><span style="color: #800000;">p </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="pc2 undis pl50 error pa"</span><span style="color: #ff0000;"> style</span><span style="color: #0000ff;">="padding-left:118px;margin-top:-10px;"</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">="card_next_error"</span><span style="color: #0000ff;">></span>错误信息<span style="color: #0000ff;"></span><span style="color: #800000;">p</span><span style="color: #0000ff;">></span> <span style="color: #008080;">19</span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="m20 tc"</span><span style="color: #0000ff;">></span> <span style="color: #008080;">20</span> <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="submit"</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">="submitCardNo"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="define_button reservation_1"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="登陆"</span> <span style="color: #0000ff;">/></span> <span style="color: #008080;">21</span> <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="button"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="取消"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="close_button closePzh ml10"</span> <span style="color: #0000ff;">/></span> <span style="color: #008080;">22</span> <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #008080;">23</span> <span style="color: #0000ff;"></span><span style="color: #800000;">form</span><span style="color: #0000ff;">></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
其中 name属性和下面js中的rules中的属性一致
2、js绑定validate事件代码如下


<span style="color: #008080;"> 1</span> $(<span style="color: #0000ff;">function</span><span style="color: #000000;">() { </span><span style="color: #008080;"> 2</span> <span style="color: #000000;"> initCardTypeFrmValidate() </span><span style="color: #008080;"> 3</span> <span style="color: #000000;"> }) </span><span style="color: #008080;"> 4</span> <span style="color: #008080;"> 5</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> initCardTypeFrmValidate() { </span><span style="color: #008080;"> 6</span> <span style="color: #008080;"> 7</span> $('#cardTypeFrm'<span style="color: #000000;">).validate({ </span><span style="color: #008080;"> 8</span> onkeyup : <span style="color: #0000ff;">false</span><span style="color: #000000;">, </span><span style="color: #008080;"> 9</span> onfocusout : <span style="color: #0000ff;">false</span><span style="color: #000000;">, </span><span style="color: #008080;">10</span> <span style="color: #000000;"> rules : { </span><span style="color: #008080;">11</span> userName : {required : <span style="color: #0000ff;">true</span><span style="color: #000000;">} </span><span style="color: #008080;">12</span> passWord : {required : <span style="color: #0000ff;">true</span><span style="color: #000000;">} </span><span style="color: #008080;">13</span> <span style="color: #000000;"> }, </span><span style="color: #008080;">14</span> <span style="color: #008080;">15</span> <span style="color: #000000;"> messages : { </span><span style="color: #008080;">16</span> userName : {required : '请输入用户名'<span style="color: #000000;">}, </span><span style="color: #008080;">17</span> passWord : {required : '请输入密码'<span style="color: #000000;">} </span><span style="color: #008080;">18</span> <span style="color: #000000;"> }, </span><span style="color: #008080;">19</span> errorElement : "p" <span style="color: #008080;">20</span> <span style="color: #000000;"> }); </span><span style="color: #008080;">21</span> }
onkeyup : false,表示键盘输入不验证,默认true
onfocusout : false,表示输入框失去焦点不验证,默认true
二、解决方案是,禁止页面的表单提交,实行js中绑定表单提交表单
1、html代码不变
<span style="color: #008080;"> 1</span> <span style="color: #0000ff;"><span style="color: #800000;">form </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="cardTypeFrm"</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 2</span> <span style="color: #0000ff;"><span style="color: #800000;">table </span><span style="color: #ff0000;">width</span><span style="color: #0000ff;">="100%"</span><span style="color: #ff0000;"> cellspacing</span><span style="color: #0000ff;">="0"</span><span style="color: #ff0000;"> cellpadding</span><span style="color: #0000ff;">="0"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="table_pzh"</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 3</span> <span style="color: #0000ff;"><span style="color: #800000;">tbody</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 4</span> <span style="color: #0000ff;"><span style="color: #800000;">tr</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 5</span> <span style="color: #0000ff;"><span style="color: #800000;">th </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="f14 tr pc1"</span><span style="color: #0000ff;">></span>用户名:<span style="color: #0000ff;"></span><span style="color: #800000;">th</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 6</span> <span style="color: #0000ff;"><span style="color: #800000;">td</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 7</span> <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="pzh_input1"</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">="userName"</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">="userName"</span> <span style="color: #0000ff;">/></span> <span style="color: #008080;"> 8</span> <span style="color: #0000ff;"></span><span style="color: #800000;">td</span><span style="color: #0000ff;">></span> <span style="color: #008080;"> 9</span> <span style="color: #0000ff;"></span><span style="color: #800000;">tr</span><span style="color: #0000ff;">></span> <span style="color: #008080;">10</span> <span style="color: #0000ff;"><span style="color: #800000;">tr</span><span style="color: #0000ff;">></span> <span style="color: #008080;">11</span> <span style="color: #0000ff;"><span style="color: #800000;">th </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="f14 tr pc1"</span><span style="color: #0000ff;">></span>密码:<span style="color: #0000ff;"></span><span style="color: #800000;">th</span><span style="color: #0000ff;">></span> <span style="color: #008080;">12</span> <span style="color: #0000ff;"><span style="color: #800000;">td</span><span style="color: #0000ff;">></span> <span style="color: #008080;">13</span> <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="pzh_input1"</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">="passWord"</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">="passWord"</span> <span style="color: #0000ff;">/></span> <span style="color: #008080;">14</span> <span style="color: #0000ff;"></span><span style="color: #800000;">td</span><span style="color: #0000ff;">></span> <span style="color: #008080;">15</span> <span style="color: #0000ff;"></span><span style="color: #800000;">tr</span><span style="color: #0000ff;">></span> <span style="color: #008080;">16</span> <span style="color: #0000ff;"></span><span style="color: #800000;">tbody</span><span style="color: #0000ff;">></span> <span style="color: #008080;">17</span> <span style="color: #0000ff;"></span><span style="color: #800000;">table</span><span style="color: #0000ff;">></span> <span style="color: #008080;">18</span> <span style="color: #0000ff;"><span style="color: #800000;">p </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="pc2 undis pl50 error pa"</span><span style="color: #ff0000;"> style</span><span style="color: #0000ff;">="padding-left:118px;margin-top:-10px;"</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">="card_next_error"</span><span style="color: #0000ff;">></span>错误信息<span style="color: #0000ff;"></span><span style="color: #800000;">p</span><span style="color: #0000ff;">></span> <span style="color: #008080;">19</span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="m20 tc"</span><span style="color: #0000ff;">></span> <span style="color: #008080;">20</span> <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="submit"</span><span style="color: #ff0000;"> id</span><span style="color: #0000ff;">="submitCardNo"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="define_button reservation_1"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="登陆"</span> <span style="color: #0000ff;">/></span> <span style="color: #008080;">21</span> <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="button"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="取消"</span><span style="color: #ff0000;"> class</span><span style="color: #0000ff;">="close_button closePzh ml10"</span> <span style="color: #0000ff;">/></span> <span style="color: #008080;">22</span> <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #008080;">23</span> <span style="color: #0000ff;"></span><span style="color: #800000;">form</span><span style="color: #0000ff;">></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
2、js代码中加入绑定提交事件
<span style="color: #008080;"> 1</span> $(<span style="color: #0000ff;">function</span><span style="color: #000000;">() { </span><span style="color: #008080;"> 2</span> <span style="color: #000000;"> initCardTypeFrmValidate() </span><span style="color: #008080;"> 3</span> <span style="color: #008000;">//</span><span style="color: #008000;">优化代码</span> <span style="color: #008080;"> 4</span> $('#cardTypeFrm').submit(<span style="color: #0000ff;">function</span><span style="color: #000000;">() { </span><span style="color: #008080;"> 5</span> <span style="color: #008080;"> 6</span> <span style="color: #0000ff;">if</span> ($('#cardTypeFrm'<span style="color: #000000;">).valid()) { </span><span style="color: #008080;"> 7</span> <span style="color: #008000;">//</span><span style="color: #008000;">通过执行的动作</span> <span style="color: #008080;"> 8</span> <span style="color: #000000;"> } </span><span style="color: #008080;"> 9</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>;<span style="color: #008000;">//</span><span style="color: #008000;">永远禁止页面表单提交</span> <span style="color: #008080;">10</span> <span style="color: #000000;"> }) </span><span style="color: #008080;">11</span> <span style="color: #000000;"> }) </span><span style="color: #008080;">12</span> <span style="color: #008080;">13</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> initCardTypeFrmValidate() { </span><span style="color: #008080;">14</span> <span style="color: #008080;">15</span> $('#cardTypeFrm'<span style="color: #000000;">).validate({ </span><span style="color: #008080;">16</span> onkeyup : <span style="color: #0000ff;">false</span><span style="color: #000000;">, </span><span style="color: #008080;">17</span> onfocusout : <span style="color: #0000ff;">false</span><span style="color: #000000;">, </span><span style="color: #008080;">18</span> <span style="color: #000000;"> rules : { </span><span style="color: #008080;">19</span> userName : {required : <span style="color: #0000ff;">true</span><span style="color: #000000;">} </span><span style="color: #008080;">20</span> passWord : {required : <span style="color: #0000ff;">true</span><span style="color: #000000;">} </span><span style="color: #008080;">21</span> <span style="color: #000000;"> }, </span><span style="color: #008080;">22</span> <span style="color: #008080;">23</span> <span style="color: #000000;"> messages : { </span><span style="color: #008080;">24</span> userName : {required : '请输入用户名'<span style="color: #000000;">}, </span><span style="color: #008080;">25</span> passWord : {required : '请输入密码'<span style="color: #000000;">} </span><span style="color: #008080;">26</span> <span style="color: #000000;"> }, </span><span style="color: #008080;">27</span> errorElement : "p" <span style="color: #008080;">28</span> <span style="color: #000000;"> }); </span><span style="color: #008080;">29</span> }

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











이 기사는 HTML & LT; Datalist & GT에 대해 논의합니다. 자동 완성 제안을 제공하고, 사용자 경험을 향상시키고, 오류를 줄임으로써 양식을 향상시키는 요소. 문자 수 : 159

이 기사는 HTML & lt; Progress & Gt에 대해 설명합니다. 요소, 그 목적, 스타일 및 & lt; meter & gt의 차이; 요소. 주요 초점은 & lt; progress & gt; 작업 완료 및 & lt; meter & gt; Stati의 경우

이 기사는 HTML & lt; meter & gt에 대해 설명합니다. 범위 내에 스칼라 또는 분수 값을 표시하는 데 사용되는 요소 및 웹 개발의 일반적인 응용 프로그램. & lt; meter & gt; & lt; Progress & Gt; 그리고 Ex

이 기사에서는 브라우저에서 직접 사용자 입력을 검증하기 위해 필요한, Pattern, Min, Max 및 Length 한계와 같은 HTML5 양식 검증 속성을 사용하는 것에 대해 설명합니다.

이 기사는 & lt; iframe & gt; 외부 컨텐츠를 웹 페이지, 공통 용도, 보안 위험 및 객체 태그 및 API와 같은 대안을 포함시키는 태그의 목적.

이 기사는 모바일 장치의 반응 형 웹 디자인에 필수적인 Viewport Meta Tag에 대해 설명합니다. 적절한 사용이 최적의 컨텐츠 스케일링 및 사용자 상호 작용을 보장하는 방법을 설명하는 반면, 오용은 설계 및 접근성 문제로 이어질 수 있습니다.

기사는 HTML5 크로스 브라우저 호환성을 보장하기위한 모범 사례에 대해 논의하고 기능 감지, 점진적 향상 및 테스트 방법에 중점을 둡니다.

이 기사는 html5 & lt; time & gt; 시맨틱 날짜/시간 표현 요소. 인간이 읽을 수있는 텍스트와 함께 기계 가독성 (ISO 8601 형식)에 대한 DateTime 속성의 중요성을 강조하여 Accessibilit를 향상시킵니다.
