jQuery validate and groups - how to avoid errorPlacement usage?
程序员文章站
2022-06-05 07:59:29
本文参照:https://*.com/questions/14146893/using-groups-with-jquery-form-validation-how 指定错误提示的位置 And this validate code: ......
本文参照:
指定错误提示的位置
<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); } })
上一篇: JS中数组去重的五种方法