我不知道为什么 form2 验证失败但 form1 通过验证(使用 jQuery 验证插件)。如何使用下面的代码使 form1 验证失败?
HTML
<form id="form1" method="get" action="">
<input type="text" id="viewName1">
<h3></h3>
</form>
<form id="form2" method="get" action="">
<input type="text" id="viewName2" required>
<h3></h3>
</form>
JAVASCRIPT
$('#form1').validate({
rules: {
viewName: 'required'
},
messages: {
viewName: '* view name is required'
},
submitHandler: function () {
$('#form1 h3').text('Form1 valid');
},
invalidHandler: function (event, validator) {
$('#form1 h3').text('Form1 invalid');
}
});
$('#form1').submit();
$('#form2').validate({
submitHandler: function () {
$('#form1 h3').text('Form1 valid');
},
invalidHandler: function (event, validator) {
$('#form1 h3').text('Form1 invalid');
}
});
$('#form2').submit();