gpt4 book ai didi

javascript - 使用不同的错误类进行验证

转载 作者:行者123 更新时间:2023-11-28 13:10:03 26 4
gpt4 key购买 nike

我的表单中有 3 个字段。我想用错误类验证姓名、年龄,用另一个错误类验证 Total_score。这是包含单个 ID 的单个表单。我该怎么做。

$('#form1').validate({
rules: {
'Name' : {
required : true
},
'Age' : {
required: true

},
'Total_score' : {
required: true
}
},
messages: {
'Name' : {
required: 'From date is required!'
},
'Age' : {
required: 'To date is required!'
},
'Total_score' : {
required: 'Score is required!'
}
},
errorClass: '?????',
errorPlacement: function(err, element) {
err.insertBefore(element);
},
submitHandler: function(form) {
form.submit();
}
});

最佳答案

尝试类似的东西

<input name="Name" data-errorclass="error-name"/>

然后

$('#form1').validate({
rules: {
'Name' : {
required : true
},
'Age' : {
required: true

},
'Total_score' : {
required: true
}
},
messages: {
'Name' : {
required: 'From date is required!'
},
'Age' : {
required: 'To date is required!'
},
'Total_score' : {
required: 'From date is required!'
}
},
errorPlacement: function(err, element) {
err.addClass(element.data('errorclass'))
err.insertBefore(element);
},
submitHandler: function(form) {
form.submit();
}
});

演示:Fiddle

关于javascript - 使用不同的错误类进行验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19355472/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com