Why onchange fires before onclick in Chrome?

匿名 (未验证) 提交于 2019-12-03 02:26:02

问题:

I would still take advantage of the expertise and availability of this community.
My question is: why if we have a code similar to

<input name="" type="checkbox"  onClick="first()" onChange="second()"> <script type="text/javascript"> function first(){     console.log('first')     } function second(){     console.log('second')     } </script> 

in firefox onclick event fires before onchange while in chrome happens the opposite?
Thanks for your answers, maybe i have not explained in the best way
I know that using onMuseDown the problem is solved but i want to understand the reason for such behavior in Chrome with the onchange and onclick event

回答1:

Because onChange is triggered due to onClick



回答2:

One dirty solution might be to use onMouseDown instead of onClick.

But I'm also wondering why you really need both ;)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!