深入學(xué)習(xí)jQuery Validate表單驗證(二)
本文實例介紹了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表單驗證有所幫助。
- jquery validate表單驗證插件
- 基于Bootstrap+jQuery.validate實現(xiàn)表單驗證
- jQuery驗證插件validate使用方法詳解
- JQuery validate插件驗證用戶注冊信息
- CKEditor無法驗證的解決方案(js驗證+jQuery Validate驗證)
- jQuery validate+artdialog+jquery form實現(xiàn)彈出表單思路詳解
- jquery.validate提示錯誤信息位置方法
- jQuery validate插件實現(xiàn)ajax驗證重復(fù)的2種方法
- jQuery validate插件submitHandler提交導(dǎo)致死循環(huán)解決方法
- jquery.validate[.unobtrusive]和Bootstrap實現(xiàn)tooltip錯誤提示問題分析
相關(guān)文章
jquery點擊獲取動態(tài)數(shù)據(jù)進行傳參問題
這篇文章主要介紹了jquery點擊獲取動態(tài)數(shù)據(jù)進行傳參問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12使用jQuery實現(xiàn)更改默認(rèn)alert框體
本文給大家介紹的是如何使用jquery 改寫Alert彈出框樣式,十分的實用,這里推薦給大家,有需要的小伙伴可以參考下。2015-04-04JQuery觸發(fā)radio或checkbox的change事件
在JQuery中,當(dāng)給radio或checkbox添加一個change事件時,如果它的值發(fā)生變化就會觸發(fā)change事件;本文將詳細(xì)介紹如何利用JQuery觸發(fā)Checkbox的change事件需要了解的朋友可以參考下2012-12-12struts2+jquery+json實現(xiàn)異步加載數(shù)據(jù)(自寫)
異步加載數(shù)據(jù)利用struts2+jquery+json實現(xiàn),具體代碼如下,感興趣的各位可以參考下哈,希望對大家有所幫助2013-06-06