jquery bind function have different execute sequence between Firefox and Chrome

just like the example: http://jsfiddle.net/nicaia/6cHxR/

the js code:

$('#checkbox_id').bind('change',function({
    alert('change');
}).bind('click',function(event){
    alert('click');event.preventDefault();
});

in chrome click the checkbox will show this:

alert 'change' and alert 'click' and the checkbox will not be checked.(the checkbox is uncheck in first.)

and in firefox click the checkbox will show this: alert 'click' and the checkbox will not be checked.(the checkbox is uncheck in first.)

the change will not be triggered in firefox. i don't know why.somebody can tell me?

thanks.


I think that chrome has a different behaviour from other browsers. I tried this code:

$('#checkbox_id').bind('change',function(){
    alert('change');
}).bind('click',function(event){
    alert('click');
});

(fiddle here: http://jsfiddle.net/6cHxR/8/) and Firefox execute the click handler before the change handler while IE and chrome execute the change handler before the click handler. I don't think that you can do a lot about that

链接地址: http://www.djcxy.com/p/56018.html

上一篇: 使用Javascript切换基于复选框的div的可见性

下一篇: jquery绑定函数在Firefox和Chrome之间有不同的执行顺序