开发者

jQuery 1.4.4 and IE6: .live('change') not triggering on checkbox until blur

Here's the code, using jQuery 1.4.4:

<input type="checkbox" value="on" offval="off" id="c5f1_Associated" name="Associated" class="editable">    
<script type="text/javascript">
$('input:checkbox').live('change', function() {
    alert('Changed!');
    // some other code
});
</script>

(The checkboxes are generated by jqGrid, so they're a little messy.)

In Chrome, the function fires immediately upon clicking on a checkbox.

In IE6, this only fires upon clicking on a checkbox and THEN clicking on something else on the page (i.e. blurs).

According to the jQuery 1.4 release notes:

change and submit events normalized

The change and submit events work reliably across browsers for both normal and live events. We override the normal change and submit events in Internet Explorer and replace them with events that work identically to the other browsers.

This behavior doesn't sound very normalized to me!

Fr开发者_开发百科om what I could find, there was bugs related to using .live("change") in IE in earlier versions of 1.4, but they were supposedly fixed in 1.4.2.

Am I doing something wrong, or is this how it's supposed to work in IE6? Will I be forced to do something like this?


The only potential problem I see with "click" is that if the user navigates to the checkbox using the tab key and then uses the space bar to select/deselect it, the event won't fire. Therefore, you'd need to add an extra bit of code for a keydown or keyup event on the checkbox:

$('input:checkbox').live('click', function(){
    checkBoxChanged();
}).keyup(function(e){
    if(e.which == 32){ //if the key pressed was the space bar
        checkBoxChanged();
    }
});

function checkBoxChanged(){
    alert('changed!');
    //other code
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜