質問

I recently came across a very very strange, and very bad bug in jQuery 1.4.1 when it comes to Firefox 16.0.1. Every other browser is fine. and older versions of Firefox are fine, and newer versions of jQuery are fine.

I have a table with some check boxes that look something like this:

<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>

and in javascript/jquery i loop through and collect all the itemIds

    var ids = new Array();

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

    });

In firefox 16.0.1, ids is populated with the url of the page. /theId like: http://blahblahblah.com/654101

I was able to work around this by just changing it to:

ids.push(thisBox.attr('itemid'));

but, I'd like to know why this happened, and if anything else is affected by this.

Here is a JS Fiddle showing the problem in all it's glory: http://jsfiddle.net/K8jRf/8/

Thanks!

役に立ちましたか?

解決

This does NOT seem to be a jQuery issue/bug but a FF16 (and FF17b) javascript issue/bug. The following html-snippet shows the special behavior of itemId on (at least) li-elements:

<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>

Looks like "itemId" has become a "special attribute/behavior" as of FF16. typeof(element.itemId) is "string", even before assignment ... FF15 behaves as expected.

他のヒント

Firefox "normalizes" attribute names to be all lowercase.

If you were using data instread of using attr you can do:

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

Js:

var itemId = $("input").data("itemId");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top