简体   繁体   English

在表单提交上禁用 Jquery UI 按钮

[英]Disable Jquery UI Button on form submit

I have a form like so:我有一个像这样的表格:

<form action="" method="post" id="form" name="form" enctype="multipart/form-data">
<input name="action" type="submit" value="Send" />
</form>

I am using the latest version of the Jquery UI Button plugin.我正在使用最新版本的 Jquery UI Button 插件。 The value of the submit button MUST be submitted.必须提交提交按钮的值。 Is there an easy way to disable the submit button after the form has been submitted, without using additional plugins such as "Lock Submit" - http://plugins.jquery.com/project/LockSubmit ?提交表单后是否有一种简单的方法可以禁用提交按钮,而无需使用其他插件,例如“锁定提交” - http://plugins.jquery.com/project/LockSubmit

Many thanks.非常感谢。

When you set the disabled property of an element, it won't be submitted.当你设置一个元素的 disabled 属性时,它不会被提交。 The workaround is to set the disabled property after the form is submitted.解决方法是在提交表单设置 disabled 属性。 You can use the setTimeout() function with a very short delay:您可以以非常短的延迟使用setTimeout() function:

$("#form").submit(function() {
    setTimeout(function() {
        // .prop() requires jQuery 1.6 or higher
        $("#form :submit").prop("disabled", true);
    }, 100);
});

Demo here演示在这里

Another trick, is to use a trick:) You can wrap the original submit button inside a div and hide it when the form submits.另一个技巧是使用技巧:) 您可以将原始提交按钮包装在 div 中,并在表单提交时将其隐藏。

Demo here演示在这里

Easy just add type="button" to button attributes like很简单,只需将 type="button" 添加到按钮属性中,例如

<button type="button" >not submit</button>

you mean你的意思是

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

? ?

$('#form').submit(function() {
  $(this).find('input[type="submit"]').disable();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM