如何禁用所有提交按钮,然后重新启用特定按钮? [英] How can I disable all the submit buttons then re-enable specific ones?
问题描述
我的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 :
-
我的方法是否适用于定义延迟时间?
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);
});
这篇关于如何禁用所有提交按钮,然后重新启用特定按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!