溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

詳解jquery.validate自定義驗(yàn)證用法

發(fā)布時(shí)間:2020-07-18 11:26:55 來源:億速云 閱讀:173 作者:小豬 欄目:web開發(fā)

小編這次要給大家分享的是詳解jquery.validate自定義驗(yàn)證用法,文章內(nèi)容豐富,感興趣的小伙伴可以來了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。

本文實(shí)例講述了jquery.validate自定義驗(yàn)證用法。分享給大家供大家參考,具體如下:

1. 自定義驗(yàn)證--成功提示

1) 添加選項(xiàng)

errorClass: "unchecked",
validClass: "checked",
errorElement: "span",
errorPlacement: function (error, element) {
 if (element.parent().find("span[for=""" + element.attr("id") + """]") != null) {
 element.parent().find("span[for=""" + element.attr("id") + """]").remove();
 }
 error.appendTo(element.parent());
},
success: function (label) {
 label.removeClass("unchecked").addClass("checked");
},

2)設(shè)置樣式

input.unchecked{border: 1px #E6594E dotted;}
span.checked {
 padding: 3px 5px 3px 21px;margin-left: 10px;margin-top: 0px;margin-bottom: 3px;adisplay: inline;
 height: 25px;line-height: 1px;font-size: 12px;aborder: 1px solid #E6594E;white-space: nowrap;
 text-align: left;color: #E6594E;background:url("/Common/Sys/Cfg/images/checked.gif") no-repeat 3px;/* #FCEAE8 */
}
span.unchecked {
 padding: 3px 5px 3px 21px;margin-left: 10px;margin-top: 0px;margin-bottom: 3px;adisplay: inline;
 height: 25px;line-height: 1px;font-size: 12px;border: 1px solid #E6594E;white-space: nowrap;
 text-align: left;color: #E6594E;background: #FCEAE8 url("/Common/Sys/Cfg/images/unchecked.gif") no-repeat 3px;     
}

2. 自定義驗(yàn)證--擇要提示

1) 添加選項(xiàng)

errorContainer: container,
errorLabelContainer: $("ul", container),
wrapper: ""li"",
meta: "validate",
errorClass: "unchecked",
validClass: "checked",

2) 設(shè)置樣式

input.unchecked{border: 1px #E6594E dotted;}
span.checked {
 padding: 3px 5px 3px 21px;margin-left: 10px;margin-top: 0px;margin-bottom: 3px;adisplay: inline;
 height: 25px;line-height: 1px;font-size: 12px;aborder: 1px solid #E6594E;white-space: nowrap;
 text-align: left;color: #E6594E;background:url("/Common/Sys/Cfg/images/checked.gif") no-repeat 3px;/* #FCEAE8 */
}
span.unchecked {
 padding: 3px 5px 3px 21px;margin-left: 10px;margin-top: 0px;margin-bottom: 3px;adisplay: inline;
 height: 25px;line-height: 1px;font-size: 12px;border: 1px solid #E6594E;white-space: nowrap;
 text-align: left;color: #E6594E;background: #FCEAE8 url("/Common/Sys/Cfg/images/unchecked.gif") no-repeat 3px;     
}
div.container {
 background-color: #eee;
 border: 1px solid red;
 margin: 5px;
 padding: 5px;
}
div.container ol li {
 list-style-type: disc;
 margin-left: 20px;
}
div.container { display: none }
.container label.error {
 display: inline;
}

3) 添加擇要標(biāo)識(shí)表記標(biāo)幟

<div class="container">
  <h5>There are serious errors in your form submission, please see below for details.</h5>
  <ul></ul>
</div>

看完這篇關(guān)于詳解jquery.validate自定義驗(yàn)證用法的文章,如果覺得文章內(nèi)容寫得不錯(cuò)的話,可以把它分享出去給更多人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI