gpt4 book ai didi

jquery - 选择 DIV 但不选择其中的链接,jQuery 问题

转载 作者:行者123 更新时间:2023-12-01 00:35:38 26 4
gpt4 key购买 nike

我有以下 div:

<div class='amazingmenu' id='menupull'>
<img src='images/down.png' width=20 height=20 align='right'/>
<div id='menupullhideme'>click the arrow to read the rest!<br /></div>
more jokes on <a href='http://www.amazingjokes.com'>amazingjokes.com</a>
</div>

单击 DIV 或图像应执行 jQuery 中的某些功能:

$('#menupull').click( function() {
alert( 'pullmenu clicked' );
});

我想让它只在我单击 DIV 或图像时提醒消息,而不是链接。尝试过这个:

     $('#menupull:not(a)').click( function() {...

但这没有用。有什么想法吗?

最佳答案

问题可能是事件冒泡..您可以做的就是在“click”事件中检查 nodeName/tagName 是否为 A,如果是就是,中止其余的函数并让 anchor 只做它的事情。

我的 jQuery 有点生疏,因为我自己不太使用它,但我认为是这样的..

$('#menupull').click( function(e) {
var target = $(e.target);
if( target.is('a') ) {
return true; // True, because we don't want to cancel the 'a' click.
}
});

关于jquery - 选择 DIV 但不选择其中的链接,jQuery 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3838758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com