我是 jQuery 新人。我已经验证可以使用我的表单(MVC 1.0 / C#):
<script type="text/javascript">
if (document.forms.length > 0) { document.forms[0].id = "PageForm"; document.forms[0].name = "PageForm"; }
$(document).ready(function() {
$("#PageForm").validate({
rules: {
SigP: { required: true }
},
messages: {
SigP: "<font color='red'><b>A Sig Value is required. </b></font>"
}
});
});
</script>
我还想隐藏“提交”按钮,以防止抽搐鼠标综合症在控制器完成和重定向之前导致重复输入(我正在使用 GPR 模式)。为此目的,进行了以下工作:
<script type="text/javascript">
//
// prevent double-click on submit
//
jQuery('input[type=submit]').click(function() {
if (jQuery.data(this, 'clicked')) {
return false;
}
else {
jQuery.data(this, 'clicked', true);
return true;
}
});
</script>
但是,我无法让两者一起工作。具体来说,如果单击“提交”按钮后验证失败(考虑到表单的工作方式,就会发生这种情况),那么我将无法再次提交表单,除非我执行浏览器刷新来重置“已单击”属性。
如何重写上面的第二个方法以不设置 clicked 属性unless表格有效吗?
Thx.
对于那些像我一样仍在寻找答案的人,我是这样做的:
$("#form1").validate({
rules: {
customer_title: "required",
customer_firstName: "required",
customer_lastName: "required"
}
},
messages: {
customer_title: "Please select a title",
customer_firstName: "Please enter a firstname",
customer_lastName: "Please enter a lastname"
}
},
submitHandler: function(form) {
//submitButtonX is the class attribute i placed on the button
$('.submitButtonX').attr('disabled', 'disabled');
form.submit();
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)