在提交中禁用按钮单击jquery

时间:2010-09-10 07:43:15

标签: jquery asp.net-mvc

在提交按钮上我想禁用该按钮,这样用户就不会多次点击。即时通讯使用jquery但它不起作用,我的代码是

setTimeout($('#btn').attr("disabled", true), 1);
return true;  

按钮被禁用但我的控制器没有调用。我究竟做错了什么?

5 个答案:

答案 0 :(得分:7)

setTimeout(function() {
    $('#btn').attr('disabled', 'disabled');
}, 1);

答案 1 :(得分:6)

我没有太多理由使用超时,我只是选择

$('#btn').attr('disabled', 'disabled');
return true;

或更准确地说,

$('#btn').click( function (e) {
    $(this).attr('disabled', 'disabled');
});

就是你所需要的一切。

有点邪恶和深奥:P

return !!$('#btn').attr('disabled', 'disabled');

那就是为了好玩。不要在你的代码中做到这一点! :)

编辑:使用最新版本的jQuery,您可以将其设为

$('#btn').attr('disabled', true);

答案 2 :(得分:1)

setTimeout($('#btn').attr('disabled', 'disabled),1);
$("#btn").removeAttr('disabled', disabled')

答案 3 :(得分:0)

这应该有效。

$("#loginButton").click(function (e) {
        var btn = $(this).clone();
        btn.prop("disabled", true)
        $(this).hide();
        $(this).after(btn);
        return true;
    });

答案 4 :(得分:-1)

试试这个:

setTimeout($('#btn').attr('disabled', 'disabled'), 1);
return true;
相关问题