HTML
<form action="#" id="MyForm" name="MyForm">
<table id="tblData">
<tr>
<td>
<label for="Fie">
A</label>
<input id="A" name="A" type="text" value="" />
</td>
</tr>
<tr>
<td>
<label for="B">
B</label>
<input id="B" name="B" type="text" value="" />
</td>
</tr>
<tr>
<td>
<span id="submitButton" class="k-button">Next</span>
</td>
</tr>
</table>
</form>
JQuery的
$(document).ready(function () {
$('#submitButton').click(function () {
$('#MyForm').submit();
if ($('#MyForm').valid()) {
alert('hi')
}
return false;
});
$('#MyForm').validate(
{
rules: {
A:
{
required: false,
range: [1, 100]
},
B: {
required: false,
range: [1, 100]
}
},
messages: {
A: {
range: jQuery.validator.format("Please enter a valid range")
},
B: {
range: jQuery.validator.format("Please enter a valid range")
}
}
,
highlight: function (element) {
$(element).closest('.invoicePrintForm').removeClass('success').addClass('error');
}
});
});
问题
单击按钮时,包括所有值均有效。假设显示警报消息。警报消息出现但刷新时消失。请检查JSFiddle。
答案 0 :(得分:1)
答案 1 :(得分:1)
$(document).ready(function () {
$('#submitButton').click(function () {
if ($('#MyForm').valid()) {
alert('valid');
}
return false;
});
});