The jquery bind function has a different execution sequence between Firefox and Chrome

as an example: http://jsfiddle.net/nicaia/6cHxR/

Js code:

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

in the chrome box, check this box:

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

and in the firefox window, click this checkbox: alert 'click', and the checkbox will not be checked. (uncheck the box first.)

the change will not start in firefox. I do not know why. Can someone tell me?

thanks.

+4
source share
1 answer

I think chrome is different 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, and IE and chrome execute the change handler before the click handler. I don’t think you can do much about it.

0
source

Source: https://habr.com/ru/post/1387718/


All Articles