欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery.validate在ie8下不支持的快速解決方法

 更新時間:2016年05月18日 11:16:54   投稿:jingxian  
下面小編就為大家?guī)硪黄狫Query.validate在ie8下不支持的快速解決方法。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考,一起跟隨小編過來看看吧

一、在ie8下回有問題的代碼

1、JQuery.validate驗證框架是通過頁面form表單提交驗證<input/>標(biāo)簽中輸入是否符合自己的規(guī)則的

<form id="cardTypeFrm">
  <table width="100%" cellspacing="0" cellpadding="0" class="table_pzh">
    <tbody>           
      <tr>
        <th class="f14 tr pc1">用戶名:</th>
        <td>
          <input type="text" class="pzh_input1" id="userName" name="userName" />
        </td>
      </tr>
      <tr>
        <th class="f14 tr pc1">密碼:</th>
        <td>
          <input type="text" class="pzh_input1" id="passWord" name="passWord" />
        </td>
      </tr>
    </tbody>
  </table>
  <p class="pc2 undis pl50 error pa" style="padding-left:118px;margin-top:-10px;" id="card_next_error">錯誤信息</p>
  <div class="m20 tc">
    <input type="submit" id="submitCardNo" class="define_button reservation_1" value="登陸" />
    <input type="button" value="取消" class="close_button closePzh ml10" />
  </div>
</form>

其中 name屬性和下面js中的rules中的屬性一致

2、js綁定validate事件代碼如下

$(function() {
      initCardTypeFrmValidate()
      })

function initCardTypeFrmValidate() {

  $('#cardTypeFrm').validate({
    onkeyup : false,
    onfocusout : false,
    rules : {
      userName : {required : true}
      passWord : {required : true}
    },

    messages : {
      userName : {required : '請輸入用戶名'},
      passWord : {required : '請輸入密碼'}
    },
    errorElement : "p"
  });
}

onkeyup : false,表示鍵盤輸入不驗證,默認(rèn)true
onfocusout : false,表示輸入框失去焦點不驗證,默認(rèn)true

二、解決方案是,禁止頁面的表單提交,實行js中綁定表單提交表單

1、html代碼不變

<form id="cardTypeFrm">
  <table width="100%" cellspacing="0" cellpadding="0" class="table_pzh">
    <tbody>           
      <tr>
        <th class="f14 tr pc1">用戶名:</th>
        <td>
          <input type="text" class="pzh_input1" id="userName" name="userName" />
        </td>
      </tr>
      <tr>
        <th class="f14 tr pc1">密碼:</th>
        <td>
          <input type="text" class="pzh_input1" id="passWord" name="passWord" />
        </td>
      </tr>
    </tbody>
  </table>
  <p class="pc2 undis pl50 error pa" style="padding-left:118px;margin-top:-10px;" id="card_next_error">錯誤信息</p>
  <div class="m20 tc">
    <input type="submit" id="submitCardNo" class="define_button reservation_1" value="登陸" />
    <input type="button" value="取消" class="close_button closePzh ml10" />
  </div>
</form>

2、js代碼中加入綁定提交事件

$(function() {
      initCardTypeFrmValidate()
      //優(yōu)化代碼
      $('#cardTypeFrm').submit(function() {

        if ($('#cardTypeFrm').valid()) {
          //通過執(zhí)行的動作
        }
        return false;//永遠(yuǎn)禁止頁面表單提交
      })
  })

function initCardTypeFrmValidate() {

  $('#cardTypeFrm').validate({
    onkeyup : false,
    onfocusout : false,
    rules : {
      userName : {required : true}
      passWord : {required : true}
    },

    messages : {
      userName : {required : '請輸入用戶名'},
      passWord : {required : '請輸入密碼'}
    },
    errorElement : "p"
  });
}

以上這篇JQuery.validate在ie8下不支持的快速解決方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論