HTML
<form action="#" id="MyForm" name="MyForm">
<table id="tblData">
<tr>
<td>
<label >
A</label>
<input id="A" name="A" type="text" value="" />
</td>
</tr>
<tr>
<td>
<span id="submitButton">Next</span>
</td>
</tr>
</table>
</form>
jQuery
$(document).ready(function () {
$('#submitButton').validate(
{
rules: {
A:
{
required: false,
range: [1, 100]
}
},
messages: {
A: {
range: jQuery.validator.format("Please enter a valid range.")
}
}
});
});
脚本文件
<script src="/Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js" ></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"
></script>
问题
如果你注意 HTML,我们有 span。我想在单击此跨度而不是输入按钮时验证表单。问题是,验证没有发生。我怎样才能做到这一点?