使用jQuery禁用控件

时间:2011-04-28 10:00:42

标签: jquery

我想禁用点击控制,因为我已将attr添加到控件'禁用',它在IE中工作正常,但在Firefox中没有。我写的代码是

$(obj).attr('disabled','disabled');

如果我遗失了什么,那么请给我一些想法。

5 个答案:

答案 0 :(得分:39)

$(obj).attr('disabled', true);

答案 1 :(得分:7)

试试这个

$(obj).attr("disabled","disable")

注意属性“已禁用”的值已“禁用”而非“已停用* el *”

答案 2 :(得分:6)

这是我用来禁用或重新启用控件的代码:

function handleControlDisplay(className, foundCount, checked) {



    var button = jQuery(className);



    if (foundCount > 0 && foundCount == checked) {

        // enable

        button.removeAttr("disabled");

    }

    else {

        // set the disabled attribute

        button.attr("disabled", "true");

    };

}

答案 3 :(得分:1)

非常完整的答案在这里:Disable/enable an input with jQuery?

TL; DR use the .prop() method

$("input").prop('disabled', true);
$("input").prop('disabled', false);

答案 4 :(得分:0)

下面是一个在单击按钮后禁用按钮的示例。请注意,您将“ this”对象传递给click事件处理程序:

<input type="button" value="Submit" onclick="disable(this)"/>

和javascript:

    <script>
     function disable(control){
       control.disabled = true;
      }
   </script>