本篇文章為大家展示了如何在jQuery中使用validate.js表單驗(yàn)證插件,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

Validate
Validate是基于jQuery的一款輕量級驗(yàn)證插件,內(nèi)置豐富的驗(yàn)證規(guī)則,還有靈活的自定義規(guī)則接口,HTML、CSS與JS之間的低耦合能讓您自由布局和豐富樣式,支持input,select,textarea的驗(yàn)證。
代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>表單驗(yàn)證插件Validate</title>
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.validate.min.js"></script>
<style>
body {
background-color: #000;
}
form {
width: 361px;
margin: 80px auto;
padding: 50px;
border: 2px solid #666;
box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);
background-color: #999;
border-radius: 10px;
box-sizing: border-box;
}
form>div {
margin-bottom: 20px;
color: #fff;
}
form>div>label {
display: inline-block;
width: 80px;
text-align: center;
}
label.error {
display: block;
width: 100%;
color: rgb(189, 42, 42);
font-size: 12px;
text-align: right;
margin-top: 5px;
}
input {
width: 170px;
height: 20px;
outline: none;
background-color: #ddd;
border: 1px solid #ddd;
border-radius: 4px;
}
.submit {
width: 170px;
margin: 30px auto 0;
}
.submit input {
background-color: #0099aa;
color: #fff;
border: 0;
padding: 5px;
height: 30px;
}
</style>
</head>
<body>
<form id="signupForm" action="" method="post">
<div>
<label for="name">姓名:</label>
<input type="text" id="name" name="name">
</div>
<div>
<label for="email">郵箱:</label>
<input type="email" id="email" name="email">
</div>
<div>
<label for="password">密碼:</label>
<input type="password" id="password" name="password">
</div>
<div>
<label for="confirm_password">確認(rèn)密碼:</label>
<input type="password" id="confirm_password" name="confirm_password">
</div>
<div class="submit">
<input type="submit" value="提交">
</div>
</form>
</body>
<script>
$(function() {
$("#signupForm").validate({
rules: {
name: "required",
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
}
},
messages: {
name: "請輸入姓名",
email: {
required: "請輸入Email地址",
email: "請輸入正確的Email地址"
},
password: {
required: "請輸入密碼",
minlength: "密碼不能小于5個(gè)字符"
},
confirm_password: {
required: "請輸入確認(rèn)密碼",
minlength: "確認(rèn)密碼不能小于5個(gè)字符",
equalTo: "兩次輸入的密碼不一致"
}
}
});
})
</script>
</html>上述內(nèi)容就是如何在jQuery中使用validate.js表單驗(yàn)證插件,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站欄目:如何在jQuery中使用validate.js表單驗(yàn)證插件-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://www.chinadenli.net/article8/dpojip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、虛擬主機(jī)、商城網(wǎng)站、動(dòng)態(tài)網(wǎng)站、網(wǎng)站建設(shè)、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容