使用jQuery禁用按钮 - IE9问题

时间:2011-02-07 16:33:30

标签: jquery internet-explorer-9

我有一段代码禁用上传按钮,直到选择上传内容为止。我只是注意到它在IE9 Beta中不起作用。我是否需要以某种方式为IE进行迭代?这是我的代码:

$("input:file").change(function(){
    if ($(this).val()) {
        $("input:submit").attr("disabled",false);
    }
});

更新:

我修改了我的代码以添加警报:

$("input:file").change(function(){
    alert("...");
    if ($(this).val()) {
        $("input:submit").removeAttr("disabled");
    }
});

在FF警报启动并启用按钮时,不会触发IE警报。

更多更新:

问题在没有代码修改的情况下继续进行。在IE9中,网址字段旁边有一个“兼容性视图”的新图标。我点击它启用,然后再次单击以禁用,问题就消失了。我的猜测,IE以某种方式阻止了jQuery并缓存了它。通过更改兼容性设置,我可能已删除缓存设置。 WEIRD!

4 个答案:

答案 0 :(得分:3)

尝试使用$("input:submit").attr("disabled","disabled");停用和$("input:submit").removeAttr("disabled")

答案 1 :(得分:0)

有些浏览器 - 显然也是IE9 - 不允许您出于安全原因访问文件输入的值。

答案 2 :(得分:0)

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

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 :(得分:0)

以下是我网站上的详细教程,展示了如何执行此操作:jQuery disable button。简而言之,使用jQuery禁用按钮的最佳方法是使用以下代码:

$('.buttonElement').attr('disabled', 'disabled'); //TO DISABLED
$('.buttonElement').removeAttr('disabled'); //TO ENABLE

希望这可以帮助别人。

相关问题