第4章 數據處理-php正則表達式-鄭阿奇(續)
704
2023-12-09
本文實例介紹了jQuery Validate表單驗證,分享給大家供大家參考,具體內容如下
一、添加一個另外一個插件jquery.validate.messages_cn.js。
改變默認提示方式。
/* * 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: "請輸入合法的網址", date: "請輸入合法的日期", dateISO: "請輸入合法的日期 (ISO).", number: "請輸入合法的數字", digits: "只能輸入整數", 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屬性來關聯字段來驗證,將校驗規則寫到 js 代碼中。
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jQuery表單驗證插件----通過name屬性來關聯字段來驗證</title> <script src="http://www.gimoo.net/scripts/jquery-1.3.1.js" type="text/javascript"></script> <script src="http://www.gimoo.net/t/1903/lib/jquery.validate.js" type="text/javascript"></script> <script src="http://www.gimoo.net/t/1903/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屬性來關聯字段來驗證</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">網址</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>
以上就是本文的全部內容,希望對大家學習jQuery Validate表單驗證有所幫助。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!