1

我有一段代码禁用上传按钮,直到选择要上传的内容。我只是注意到它在 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 并将其缓存。通过更改兼容性设置,我可能已经删除了缓存设置。诡异的!

4

4 回答 4

3

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

于 2011-02-07T16:37:25.407 回答
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");

    };

}
于 2011-04-30T12:49:00.890 回答
0

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

于 2011-02-07T16:39:13.700 回答
0

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

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

希望这可以帮助某人。

于 2013-01-30T08:19:36.270 回答