IE中的隐藏字段被视为禁用? [英] hidden fields in IE are considered disabled?

查看:159
本文介绍了IE中的隐藏字段被视为禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的示例页面,我得到不同的输出为IE比我做其他浏览器。

With the below sample page I get a different output for IE than I do for other browsers.

<html>
<head>
    <title>hidden fields test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
</head>
<body>
    <form>
        <input type="hidden" value="hidden1" />
        <input type="hidden" value="hidden2" />
        <input type="text" value="text1" />
        <input type="text" value="text2" />
    </form>
    <script type="text/javascript">
        $(function() {
            var inputs = $("form input:enabled");
            var concatenated = '';
            inputs.each(function() {
                concatenated = concatenated + $(this).val();
            });

            alert(concatenated);
        });
    </script>
</body>
</html>

对于IE 8(8.0.7600.16385),输出为text1text2 648.127)和Firefox(3.6.13),它是hidden1hidden2text1text2。这对我来说是意想不到的。这是一个在IE或jQuery中的错误,或者只是一个预期的浏览器的差异jQuery不在?

With IE 8 (8.0.7600.16385), the output is "text1text2", with Chrome (10.0.648.127) and Firefox (3.6.13) it is "hidden1hidden2text1text2". This was unexpected to me. Is this a bug in IE or jQuery, or just an expected difference in browsers that jQuery is not accounting for?

在IE中隐藏的字段总是带有隐藏的disabled?

Do hidden fields in IE always carry an implicit "disabled"?

推荐答案

似乎FF和Chrome假设即使一个元素被隐藏,如果它没有被禁用,它被认为是启用。在IE中,似乎没有做出假设,并且隐藏输入既不被认为是启用或禁用。 $('input:enabled')或$('input:disabled')在IE中使用隐藏的元素运行:

It seems that FF and Chrome assume that even if an element is hidden if it is not disabled it is considered enabled. In IE it seems that assumption is not made and the hidden input is neither considered enabled or disabled. Neither $('input:enabled') or $('input:disabled') runs with hidden elements in IE:

这里简单测试: http://jsfiddle.net/KFu4t/4/

两者FF和Chrome显示输入已启用,但IE未显示已启用或禁用。

Both FF and Chrome show the input as enabled but IE doesn't show it enabled OR disabled.

在jQuery注释上注意:启用:

It is noted on the jQuery comments for :enabled that:


在文档中没有具体说明,但是这似乎不包括hidden类型的输入。

It's not stated specifically in the docs, but this doesn't seem to include inputs of type "hidden".

http://api.jquery.com/ enabled-selector /

这篇关于IE中的隐藏字段被视为禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆