禁用表单提交上的提交按钮 [英] Disable submit button on form submit

查看:173
本文介绍了禁用表单提交上的提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这段代码,点击后禁用我网站上的提交按钮:

I wrote this code to disable submit buttons on my website after the click:

$('input[type=submit]').click(function(){
    $(this).attr('disabled', 'disabled');
});

不幸的是,它不发送表格。我该如何解决这个问题?

Unfortunately, it doesn't send the form. How can I fix this?

编辑
我想绑定提交,而不是表单:)

EDIT I'd like to bind the submit, not the form :)

推荐答案

执行 onSubmit()

$('form#id').submit(function(){
    $(this).find(':input[type=submit]').prop('disabled', true);
});

在实际触发提交事件之前,您正在完全禁用该按钮。

What is happening is you're disabling the button altogether before it actually triggers the submit event.

您可能还应考虑使用ID或CLASS来命名元素,因此不要在页面上选择提交类型的所有输入。

You should probably also think about naming your elements with IDs or CLASSes, so you don't select all inputs of submit type on the page.

演示: http://jsfiddle.net/userdude/ 2hgnZ /

(注意,我使用 preventDefault()返回false 所以表单在示例中没有实际提交;请在使用时将其保留。)

(Note, I use preventDefault() and return false so the form doesn't actual submit in the example; leave this off in your use.)

这篇关于禁用表单提交上的提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆