当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jquery.validate自定义验证用法实例分析【成功提示与择要提示】

jquery.validate自定义验证用法实例分析【成功提示与择要提示】

2020年06月14日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery.validate自定义验证用法。分享给大家供大家参考,具体如下:

1. 自定义验证--成功提示

1) 添加选项

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)设置样式

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. 自定义验证--择要提示

1) 添加选项

errorcontainer: container,
errorlabelcontainer: $("ul", container),
wrapper: ""li"",
meta: "validate",
errorclass: "unchecked",
validclass: "checked",

2) 设置样式

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) 添加择要标识表记标帜

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网