jQuery validate and groups - how to avoid errorPlacement usage?
程序员文章站
2024-02-03 11:41:58
本文参照: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); } })
上一篇: Vue 组件之间传值