admin管理员组文章数量:1287598
I have a two-level ul/li menu where the li can fire of different onclick-events.
It seems as the parent-event (ul li), is fired when clicking one ul li ul li-item.
Can I avoid this an easy way.
(I'm considering using timer to trap second event, but think of it as an ugly fix...)
Regards, /T
I have a two-level ul/li menu where the li can fire of different onclick-events.
It seems as the parent-event (ul li), is fired when clicking one ul li ul li-item.
Can I avoid this an easy way.
(I'm considering using timer to trap second event, but think of it as an ugly fix...)
Regards, /T
Share Improve this question asked Nov 12, 2010 at 12:00 TesonTeson 6,7369 gold badges50 silver badges70 bronze badges 1- are you using straight javascript or a js library to set events? – fcalderan Commented Nov 12, 2010 at 12:04
2 Answers
Reset to default 10I suppose you have to stop the event bubbling
so if you are using straight javascript you have event.cancelBubble = true
otherwise if you're using jQuery you have event.stopPropagation()
or event.stopImmediatePropagation()
http://api.jquery./category/events/event-object/
Instead of event.stopPropagation()
consider:
function myFunction() {
if (event.myFunctionResolved == undefined) {
event.myFunctionResolved = true;
// your logic here
}
}
The advantage here is that the event won't be stopped and hence other scripts that might be listening for that event will be executed.
本文标签: javascriptavoid double events (onclick) with nested ulliStack Overflow
版权声明:本文标题:javascript - avoid double events (onclick) with nested ulli - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741292359a2370623.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论