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

深入學(xué)習(xí)jQuery Validate表單驗證(二)

 更新時間:2016年01月18日 16:34:49   作者:daliu_it  
這篇文章主要針對jQuery Validate表單驗證為大家進行詳細(xì)介紹,通過name屬性來關(guān)聯(lián)字段來驗證,改變默認(rèn)的提示信息,將校驗規(guī)則寫到j(luò)s代碼中,感興趣的小伙伴們可以參考一下

本文實例介紹了jQuery Validate表單驗證,分享給大家供大家參考,具體內(nèi)容如下

一、添加一個另外一個插件jquery.validate.messages_cn.js。
改變默認(rèn)提示方式。

/*
 * Translated default messages for the jQuery validation plugin.
 * Language: CN
 * Author: Fayland Lam <fayland at gmail dot com>
 */
jQuery.extend(jQuery.validator.messages, {
    required: "必選字段",
    remote: "請修正該字段",
    email: "請輸入正確格式的電子郵件",
    url: "請輸入合法的網(wǎng)址",
    date: "請輸入合法的日期",
    dateISO: "請輸入合法的日期 (ISO).",
    number: "請輸入合法的數(shù)字",
    digits: "只能輸入整數(shù)",
    creditcard: "請輸入合法的信用卡號",
    equalTo: "請再次輸入相同的值",
    accept: "請輸入擁有合法后綴名的字符串",
    maxlength: jQuery.format("請輸入一個長度最多是 {0} 的字符串"),
    minlength: jQuery.format("請輸入一個長度最少是 {0} 的字符串"),
    rangelength: jQuery.format("請輸入一個長度介于 {0} 和 {1} 之間的字符串"),
    range: jQuery.format("請輸入一個介于 {0} 和 {1} 之間的值"),
    max: jQuery.format("請輸入一個最大為 {0} 的值"),
    min: jQuery.format("請輸入一個最小為 {0} 的值")
});

二、jQuery表單驗證插件----通過name屬性來關(guān)聯(lián)字段來驗證,將校驗規(guī)則寫到 js 代碼中。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>jQuery表單驗證插件----通過name屬性來關(guān)聯(lián)字段來驗證</title>
 <script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
 <script src="lib/jquery.validate.js" type="text/javascript"></script>
 <script src="lib/jquery.validate.messages_cn.js" type="text/javascript"></script>
 
<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>

 <script type="text/javascript">
 $(document).ready(function(){

  $("#commentForm").validate({
    rules: {
      username: {
        required: true,
        minlength: 2
      },
      email: {
        required: true,
        email: true
      },
      url:"url",
      comment: "required"
    }
   });

 });
 </script>
 
</head>
<body>
 

 <form class="cmxform" id="commentForm" method="get" action="">
 <fieldset>
  <legend>jQuery表單驗證插件----通過name屬性來關(guān)聯(lián)字段來驗證</legend>
  <p>
   <label for="cusername">姓名</label>
   <em>*</em><input id="cusername" name="username" size="25" />
  </p>
  <p>
   <label for="cemail">電子郵件</label>
   <em>*</em><input id="cemail" name="email" size="25" />
  </p>
  <p>
   <label for="curl">網(wǎng)址</label>
   <em> </em><input id="curl" name="url" size="25" value="" />
  </p>
  <p>
   <label for="ccomment">你的評論</label>
   <em>*</em><textarea id="ccomment" name="comment" cols="22"></textarea>
  </p>
  <p>
   <input class="submit" type="submit" value="提交"/>
  </p>
 </fieldset>
 </form>
 
</body>
</html>

以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)jQuery Validate表單驗證有所幫助。

相關(guān)文章

最新評論