如何禁用所有提交按钮,然后重新启用特定按钮? [英] How can I disable all the submit buttons then re-enable specific ones?

查看:67
本文介绍了如何禁用所有提交按钮,然后重新启用特定按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的asp.net mvc 3 Web应用程序中有以下脚本,当用户点击它们时禁用所有提交按钮以防止连续提交相同的数据:

I have the following script inside my asp.net mvc 3 web application to disable all the submit buttons when the user click on them to prevent successive submition for the same data:

$(document).ready(function () {
    $("input[type='submit']").click(function () {
        $(this).prop('disabled', true);
    });
});

上述脚本工作正常,但禁用搜索等提交按钮会阻止用户进行另一次搜索,除非他们刷新页面。
所以我想我是否可以修改我的脚本以便在2秒之后重新启用提交按钮。
我厌倦了使用 delay()但是它不起作用。

The above script is working fine, but disabling the submit buttons such as "search" will prevent the users from performing another search unless they refresh the page. So I was thinking if I can modify my script to re-enable the submit button after let say 2 seconds. I tired to use delay() but it did not work.

所以我有了下面的内容问题:

So I have the folloiwng questions :


  1. 我的方法是否适用于定义延迟时间?

  1. Is my approach valid for defining a delay time?

如何定义延迟时间然后重新启用按钮。

How I can define a delay time and then re-enable the button.


推荐答案

$("input[type='submit']").click(function () {
        var $this = $(this);
        $this.prop('disabled', true);
        setTimeout(function() {
          $this.prop('disabled', false);
        },2000);
    });

DEMO

这篇关于如何禁用所有提交按钮,然后重新启用特定按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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