使用 jquery 禁用提交按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13194926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:23:43  来源:igfitidea点击:

disable submit button using jquery

jquery

提问by Randy

I want to disable submit button in my form once it s clicked to restrict user to click it again and again i tried this with jquery

我想在我的表单中禁用提交按钮,一旦它被点击以限制用户一次又一次地点击它我用 jquery 尝试了这个

$('form').submit(function()
{  
    var formId = this.id;
    if (formId != ''){
        $('#'+formId+' :input[type=submit]').attr('disabled',true);
        this.submit();
    }
}); 

my problem s that i have two submit button s in my page which i m checking in controller to direct but i m not getting any post values once i disable the submit button in my form. Is there any other way to prevent user to restrict multiple clicks ?

我的问题是我的页面中有两个提交按钮,我正在检查控制器以进行定向,但一旦我禁用表单中的提交按钮,我就没有得到任何帖子值。有没有其他方法可以防止用户限制多次点击?

回答by Abhilash

Have an id or a name for the submitbutton. Disable that button only

submit按钮的 id 或名称。仅禁用该按钮

For example:

例如:

HTML

HTML

<form id="frm_name">
     <input type="submit" id="btn_submit" value="Submit" />
</form>

jQuery

jQuery

...
if (formId != ''){
    $('#btn_submit').attr('disabled',true);
    this.submit();
}
...

回答by immayankmodi

In my case $('#btn_submit').prop("disabled", true);worked!

在我的情况下$('#btn_submit').prop("disabled", true);工作!

Update:

更新:

I was using kendo grid inside some specific rows I want to disable Editand Deleteinline buttons. I tried many alternate ways to disable it but .prop()worked like charm!

我在一些特定的行中使用了剑道网格,我想禁用EditDelete内联按钮。我尝试了许多替代方法来禁用它,但.prop()就像魅力一样!

回答by immayankmodi

You can also disable the event like this,

您也可以像这样禁用事件,

$('form').submit(function(e)
{ 

e.preventDefault();
//then carry out another way of submitting the content.

}