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

JQuery validate插件Remote用法大全

 更新時(shí)間:2016年05月15日 09:14:32   作者:wildfox  
validate是一個(gè)基于Jquery的表單驗(yàn)證插件,利用他的remote可以用來(lái)自定義遠(yuǎn)程驗(yàn)證,這篇文章主要介紹了JQuery validate插件Remote用法大全的相關(guān)資料,需要的朋友可以參考下

jquery.validate是jquery旗下的一個(gè)驗(yàn)證框架,借助jquery的優(yōu)勢(shì),我們可以迅速驗(yàn)證一些常見(jiàn)的輸入,還可以自己擴(kuò)充自己的驗(yàn)證方法,并且對(duì)國(guó)際化也有很好的支

JQuery.validate.js 在表單驗(yàn)證中經(jīng)常使用,初學(xué),對(duì)于其中Remote的使用說(shuō)明一下.

. 基本解釋

JQuery主要用于DOM樹(shù)和CSS樹(shù)的檢索和后面的操作的一套方法,JQuery.validate.js是對(duì)JQuery的一個(gè)插件,可以認(rèn)為是對(duì)JQuery在某個(gè)特殊場(chǎng)景下的擴(kuò)展,而Validate就是對(duì)表單驗(yàn)證提供的擴(kuò)展。

. 場(chǎng)景解釋

用戶(hù)進(jìn)行注冊(cè)用戶(hù)的時(shí)候,要異步的判斷用戶(hù)名是否存在,給出提示信息。

. 通過(guò)案例學(xué)習(xí)

Html和JavaScript結(jié)合的腳本.

<!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,
/*忽略某些元素不做驗(yàn)證*/
//ignore: ".ignore",
/* 更改錯(cuò)誤信息顯示的位置
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: "請(qǐng)輸入姓名",
remote: "請(qǐng)輸入姓名,remote"},
phonenum: {
required: "請(qǐng)輸入手機(jī)號(hào)",
digits: "存在字符,非法手機(jī)號(hào)",
rangelength: "手機(jī)號(hào)位數(shù)不對(duì)"},
email: {
required: "請(qǐng)輸入Email地址",
email: "請(qǐng)輸入正確的email地址"},
password: {
required: "請(qǐng)輸入密碼",
minlength: jQuery.format("密碼不能小于{}個(gè)字 符")},
confirm_password: {
required: "請(qǐng)輸入確認(rèn)密碼",
minlength: "確認(rèn)密碼不能小于個(gè)字符",
equalTo: "兩次輸入密碼不一致不一致"}
},
submitHandler: function(form){
alert("驗(yàn)證通過(guò)");} 
});
}); 
</script>
</head>
<body>
<form id="signupForm" method="post" action="">
<p>
<label for="firstname">姓氏</label>
<input id="firstname" name="firstname" />
</p>
<p>
<label for="phonenum">手機(jī)</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">確認(rèn)密碼</label>
<input id="confirm_password" name="confirm_password" type="password" />
</p>
<p>
<input class="submit" type="submit" value="提交"/>
</p>
</form>
</body>
</html>

后臺(tái)PHP代碼 BaseFunction.php

<?php
function WriteLog($msg)
{
$filename = dirname(__FILE__) ."\\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");
}
}
?>

  后臺(tái)PHP代碼 Learn.php

<?php
require("BaseFunction.php");
CheckUser('firstname');
?>

以上所述是小編給大家介紹的JQuery validate插件Remote用法大全的相關(guān)知識(shí),希望對(duì)大家以上幫助!

相關(guān)文章

最新評(píng)論