jquery.validate是jquery旗下的一個驗證框架,借助jquery的優勢,我們可以迅速驗證一些常見的輸入,還可以自己擴充自己的驗證方法,并且對國際化也有很好的支
JQuery.validate.js 在表單驗證中經常使用,初學,對于其中Remote的使用說明一下.
. 基本解釋
JQuery主要用于DOM樹和CSS樹的檢索和后面的操作的一套方法,JQuery.validate.js是對JQuery的一個插件,可以認為是對JQuery在某個特殊場景下的擴展,而Validate就是對表單驗證提供的擴展。
. 場景解釋
用戶進行注冊用戶的時候,要異步的判斷用戶名是否存在,給出提示信息。
. 通過案例學習
Html和JavaScript結合的腳本.
<!DOCTYPE html PUBLIC "-//WC//DTD XHTML . Transitional//EN" "http://www.w.org/TR/xhtml/DTD/xhtml-transitional.dtd"><html xmlns="http://www.w.org//xhtml"><head><script src="../includes/libraries/javascript/jquery.js" type="text/javascript" charset="utf-" ></script><script src="../includes/libraries/javascript/jquery.plugins/jquery.validate.js" type="text/javascript" charset="utf-"></script><script type="text/javascript">$().ready(function() {$("#signupForm").validate({debug: false,onkeyup:false,/*忽略某些元素不做驗證*///ignore: ".ignore",/* 更改錯誤信息顯示的位置Default:errorPlacement: function(error, element) { error.appendTo(element.parent()); } error.appendTo(element.parent());*//*submitHandle: function(form){alert("submited!");form.submit();},*/rules: {/*firstname: { required: function(){ return true;}},*/firstname: {required: true,remote: {url: "Learn.php",type: "post",//DataType: "json",data: {firstname: function(){return $("#firstname").val();}}}},phonenum: {required: true,digits: true,rangelength: [,]},email: {required: true,email: true},password: {required: true,minlength: },confirm_password: {required: true,minlength: ,equalTo: "#password"}},messages: {firstname: {required: "請輸入姓名",remote: "請輸入姓名,remote"},phonenum: {required: "請輸入手機號",digits: "存在字符,非法手機號",rangelength: "手機號位數不對"},email: {required: "請輸入Email地址",email: "請輸入正確的email地址"},password: {required: "請輸入密碼",minlength: jQuery.format("密碼不能小于{}個字 符")},confirm_password: {required: "請輸入確認密碼",minlength: "確認密碼不能小于個字符",equalTo: "兩次輸入密碼不一致不一致"}},submitHandler: function(form){alert("驗證通過");} });}); </script></head><body><form id="signupForm" method="post" action=""><p><label for="firstname">姓氏</label><input id="firstname" name="firstname" /></p><p><label for="phonenum">手機</label><input id="phonenum" name="phonenum" /></p><p><label for="email">郵件</label><input id="email" name="email" /></p><p><label for="password">密碼</label><input id="password" name="password" type="password" /></p><p><label for="confirm_password">確認密碼</label><input id="confirm_password" name="confirm_password" type="password" /></p><p><input class="submit" type="submit" value="提交"/></p></form></body></html>
后臺PHP代碼 BaseFunction.php
<?phpfunction WriteLog($msg){$filename = dirname(__FILE__) ."http://Debug.log";$handler = null;if (($handler = fopen($filename, 'ab+')) !== false){fwrite($handler, "/n".'['.date('Y-m-d H:i:s').']'."/t".$msg);fclose($handler);}}function CheckUser($UserName) { if( $_REQUEST[$UserName] == 'php' ){exit("false");}else{exit("true");}}?>
后臺PHP代碼 Learn.php
<?phprequire("BaseFunction.php");CheckUser('firstname');?>
以上所述是小編給大家介紹的JQuery validate插件Remote用法大全的相關知識,希望對大家以上幫助!
新聞熱點
疑難解答