我正在尝试进行表单验证和.bind('submit')(用spinner替换提交按钮)以便很好地一起玩。
我的JS代码是
$.metadata.setType("attr", "validate");
$(document).ready(function() {
$("#selecttest").validate({
rules: {
field: {
required: true,
email: true
}
}
});
$('#selecttest').bind('submit', function() {
$('#div-loading').show();
$('#div-submit').hide();
});
});
,表格是:
<form id="selecttest" method="post" action="submit.php">
Please enter your Email:
<input type="email" name="email" id="email" style="font-size: 30px;" class="inputtext required email" size="30" onKeyDown="if(event.keyCode==13) event.keyCode=9;" validate="required:true" title=""><br><br>
<input type="checkbox" name="tos" value="tos" class="required" checked/>I agree to the <a>terms and conditions</a><br>
<div id="div-loading" style="display:none;">
<img src="../images/loading.gif" class="Loading">
</div>
<br>
<div id="div-submit">
<INPUT type="submit" value="Submit" class="ButtonSubmit">
</div>
</form>
这两个函数彼此独立地工作,我只是无法弄清楚如何绑定第二个(显示/隐藏),它只运行一次验证和提交。
答案 0 :(得分:4)
http://docs.jquery.com/Plugins/Validation/validate
$("#selecttest").validate({
rules: {
field: {
required: true,
email: true
}
},
submitHandler: function(form) {
$('#div-loading').show();
$('#div-submit').hide();
form.submit();
}
});