我想在用户提交表单后禁用提交按钮,以便他不能点击两次提交按钮。因此,我在页面中编写了以下javascript代码:
$(document).ready(function(){
$("form").submit(function(){
$("form").find('input[type=submit]').attr('disabled', 'disabled');
});
})
这个方法很好用。但是当我应用jquery验证库并添加以下代码时: $(document).ready(function(){ $("form").submit(function(){ $("form").find('input[type=submit]').attr('disabled', 'disabled'); });
$("form").validate({ errorClass: "jqueryError", errorElement: 'label', success: 'jqueryValid', messages: { TopicCategory: { required: 'Please choose a category for topic.' }, TopicSubcategoryId: { required: 'Please choose a subcategory for topic.' }, TopicTitle: { required: 'Please enter a title for topic.' } } }); })
即使网站中有不完整的输入(即有错误的表单且要求用户正确填写),提交表单后提交按钮也会被禁用。当用户纠正所有错误并完成表单时,提交按钮仍然被禁用。
如何先检查表单中是否有错误,然后禁用提交按钮,最后提交它呢?
谢谢
这个方法很好用。但是当我应用jquery验证库并添加以下代码时: $(document).ready(function(){ $("form").submit(function(){ $("form").find('input[type=submit]').attr('disabled', 'disabled'); });
$("form").validate({ errorClass: "jqueryError", errorElement: 'label', success: 'jqueryValid', messages: { TopicCategory: { required: 'Please choose a category for topic.' }, TopicSubcategoryId: { required: 'Please choose a subcategory for topic.' }, TopicTitle: { required: 'Please enter a title for topic.' } } }); })
即使网站中有不完整的输入(即有错误的表单且要求用户正确填写),提交表单后提交按钮也会被禁用。当用户纠正所有错误并完成表单时,提交按钮仍然被禁用。
如何先检查表单中是否有错误,然后禁用提交按钮,最后提交它呢?
谢谢
:submit
selector,以及接受一个元素作为搜索对象的$
函数变体。 - SLaks