[英]How JQuery events triggered depending on Browser
I have a checkbox "chk" in my code. 我的代码中有一个复选框“ chk”。 I have onclick event for the checkbox and in jQuery I have
(chk).change(function)
. 我有复选框的onclick事件,在jQuery中,我有
(chk).change(function)
。 The weird thing now is in FireFox the onclick function is executed first and then the change function is executed. 现在奇怪的是在FireFox中,先执行onclick函数,然后执行change函数。 But in Chrome/IE the change function is executing first and then the onclick function is executed.
但是在Chrome / IE中,更改功能会先执行,然后再执行onclick功能。 Can anyone help with why this is working so.
任何人都可以帮忙解决这个问题。
Your question is interesting and doing the test i noticed that even with a code similar to this the problem remains. 您的问题很有趣,在进行测试时,我注意到即使使用类似于此的代码,问题仍然存在。
In Chrome the onclick event fires after onchange and also we revert the events in input type the problem remains 在Chrome中,onchange事件触发后会触发onclick事件,而且我们将事件恢复为输入类型后,问题仍然存在
<input name="" type="checkbox" onChange="second()" onClick="first()" >
<script type="text/javascript">
function first(){
console.log('first')
}
function second(){
console.log('second')
}
</script>
I tried to ask a question to the community ( this ) 我试图向社区问一个问题( this )
but, until now, i haven't received answers. 但是直到现在,我还没有收到答案。
The only answer that I can give you is that your problem could be solved by using onclick instead of onMouseDown 我只能给您的答案是,可以使用onclick代替onMouseDown解决您的问题
<input name="" type="checkbox" value="" id='chk' onMouseDown="first()">
<script type="text/javascript">
function first(){
console.log('first')
}
$(document).ready(function(){
$('#chk').on('change',function(){
console.log('second')
})
})
</script>
I'm sorry not to be able to help you more, 很抱歉无法为您提供更多帮助,
But that's all i could do, sorry for my english, and bye. 但这就是我所能做的,对不起我的英语,再见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.