【问题标题】:Input appears disabled in IE, but is not disabled输入在 IE 中显示为禁用,但未禁用
【发布时间】:2012-06-11 17:00:04
【问题描述】:

我的页面上有一个输入(按钮),如下所示:

<input id="the-button" type="submit" class="btn" value="Click me!">

我正在覆盖表单提交操作,因此我可以在实际提交表单之前检查一些事情。在执行此操作之前,我禁用了该按钮,因此用户不会再次单击它,因此他们可以看到该页面正在运行。

$("#the-button").attr("disabled", true);

如果我决定不提交表单,我会重新启用该按钮。

$("#the-button").attr("disabled", false);

这在 Chrome/Firefox 中按预期工作,但在 IE8 中,按钮 似乎 被禁用,但您仍然可以单击它。所需的行为是看起来已启用,但在 IE 中显示为灰色。

【问题讨论】:

    标签: jquery internet-explorer-8 disabled-input


    【解决方案1】:

    如果您使用的是 jQuery 1.6+,那么您真的应该使用 .prop,因为 'disabled' 是 element 的一个属性

    $("#the-button").prop("disabled", true);
    $("#the-button").prop("disabled", false);
    

    http://api.jquery.com/prop/

    【讨论】:

      【解决方案2】:

      正如 Wiry 所说,使用 prop 是最好的方法,但是如果你坚持使用旧版本的 jQuery,你可以“镜像”IE 的语句,例如:

      $("#the-button").attr("disabled", ""); // Enabled
      $("#the-button").attr("disabled", "disabled"); // Disabled
      

      ReadOnly 也是如此(显然在文本框等上)

      $("#the-button").attr("readonly", ""); // Read Write
      $("#the-button").attr("readonly", "readonly"); // Read Only
      

      【讨论】:

        猜你喜欢
        • 2016-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-11
        • 1970-01-01
        • 2010-10-10
        • 2017-06-13
        相关资源
        最近更新 更多