开发者

jQuery not finding disabled elements consistently in Opera

I have an HTML table in which the first column's cells each contain a check box with a class 'myClass'. I have also put a checkbox into this column's header cell, and I want it to work so that checking or unchecking the header cell sets or unsets all the row checkboxes too. I have this code in the header checkbox's click handler:

if (jQuery(event.target).attr('checked') === true) {
    alert(jQuery('td .myClass:enabled').length);
    jQuery('td .myClass:enabled').attr('checked', 'checked');
} else {
    alert(jQuery('td .myClass:enabled').length);
    jQuery('td .myClass:enabled').removeAttr('checked');
}

Three rows have enabled checkboxes and five disabled ones.

The code works开发者_StackOverflow中文版 fine in IE8, FF3.6 and Chrome 7.0. However, in Opera 10.63 the first time I check the header cell all eight rows get checked. Subsequently the code works as expected.

The alert statements confirm this, showing '3' every time except the first.

Is this an Opera bug? If so, is there a workaround?


Strange synchronisity - I've just analysed a bug report I think is the same issue a couple of hours ago :)

Yes, this is probably a bug where Opera fails to apply the pseudo-class enabled correctly on elements that were created in the DOM and later inserted into the document.

It may be an acceptable workaround to use class names instead of :enabled. Or inverse .checked property twice on all checkboxes from onload, perhaps? It sounds like toggling the disabled or checked status back and forth will make Opera handle this fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜