jQuery validate and groups - how to avoid errorPlacement usage?
本文参照:https://stackoverflow.com/questions/14146893/using-groups-with-jquery-form-validation-how
指定错误提示的位置
<form id="myform">
First Name: <input type="text" name="fname" id="fname"/><br>
Last Name: <input type="text" name="lname" id="lname"/><br>
<input type="submit"/>
</form>
And this validate code:
$("#myform").validate({
rules: {
fname: { required: true },
lname: { required: true }
},
groups: {
username: "fname lname"
},
errorPlacement: function(error, element) {
if (element.attr("name") == "fname"
|| element.attr("name") == "lname" )
error.insertAfter("#lname");
else
error.insertAfter(element);
}
})
posted on 2018-08-31 10:12 freeliver54 阅读(402) 评论(0) 编辑 收藏 举报