jQuery 1.4.1和Firefox 16.0.1奇怪的属性问题

时间:2012-10-15 13:52:21

标签: jquery attributes jquery-1.4 firefox-16

在Firefox 16.0.1中,我最近遇到了jQuery 1.4.1中一个非常奇怪且非常糟糕的错误。其他浏览器都没问题。和旧版本的Firefox都很好,更新版本的jQuery很好。

我有一个带有一些复选框的表格,如下所示:

<table class="EntityTable">
<tbody>
    <tr>
        <td>
            <input type="checkbox" class="IdCheckBox" id="Checkfor654100" name="Checkfor654100" itemId="654100" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" class="IdCheckBox" id="Checkfor654101" name="Checkfor654101" itemId="654101" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" class="IdCheckBox" id="Checkfor654102" name="Checkfor654102" itemId="654102" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" class="IdCheckBox" id="Checkfor654103" name="Checkfor654103" itemId="654103" />
        </td>
    </tr>
</tbody>
</table>

并在javascript / jquery中循环并收集所有itemIds

    var ids = new Array();

    $('input.IdCheckBox:checked').each(function(){
       var thisBox = $(this);
       ids.push(thisBox.attr('itemId'));

    });

在firefox 16.0.1中,使用页面的url填充ids。 / theId喜欢:http://blahblahblah.com/654101

我只需将其更改为:

即可解决此问题
ids.push(thisBox.attr('itemid'));

但是,我想知道为什么会发生这种情况,如果还有其他因素影响了这一点。

这是一个JS小提琴,显示出所有荣耀的问题: http://jsfiddle.net/K8jRf/8/

谢谢!

2 个答案:

答案 0 :(得分:4)

这似乎不是jQuery问题/ bug,而是FF16(和FF17b)javascript问题/ bug。 以下html-snippet显示了(至少)li-elements上的itemId的特殊行为:

<html><body><ul><li id="li1"></li></ul><script>
var element = document.getElementById("li1");
// assign to bla
element.bla = "hello";
// after
alert( element.bla ); // ok -> hello
// assign
element.itemId = "hello";
// after
alert( element.itemId ); // nok -> <file uri>hello
</script>
</body>
</html>

看起来&#34; itemId&#34;已成为&#34;特殊属性/行为&#34;截至FF16。 typeof(element.itemId)是&#34; string&#34;,甚至在分配之前...... FF15表现得如预期的那样。

答案 1 :(得分:2)

Firefox“将”属性名称规范化为全小写。

如果您正在使用data instread使用attr,您可以执行以下操作:

<input type="checkbox" class="IdCheckBox"
                id="Checkfor654101" name="Checkfor654101" data-itemId="654101" />

JS:

var itemId = $("input").data("itemId");