[英]Jquery: submenu appears with hover function but not click function
I have a multi-layered navigation the consists of 3 <ul>
s nested in each other (obviously a menu with hidden submenus the show on click). 我有一个多层导航,该导航由彼此嵌套的3个
<ul>
组成(显然是一个带有隐藏子菜单的菜单,单击时显示)。
I have created a script to show the 2nd level <ul>
s if one of the first is clicked. 我创建了一个脚本来显示第二级
<ul>
如果单击了第一级之一。 This works fine: 这工作正常:
//CLICK MAIN NAV SHOW 2nd LAYER NAV
$("#ctamenu ul li").not("#ctamenu ul li ul li, .thirdsub").click(function() {
$(this).children('ul').stop().delay(200).slideDown(300);
});//END CLICK FUNCTION
But when I repeat this for the 3rd level <ul>
s it does not work properly: 但是,当我在第三级
<ul>
重复此操作时,它将无法正常工作:
$("#ctamenu ul li ul li").click(function () {
$(this).find('.thirdsub').stop().show(300);
});
What is strange is that when I inspect the elements in the browser the display: none
css is definitely removed from the thirdsub element. 奇怪的是,当我检查浏览器中的元素时,
display: none
绝对不会从Thirdsub元素中删除display: none
CSS。 I even get a coloured outline where Chrome is showing me where the element should be. 我什至在Chrome向我展示元素应位于的位置时得到了彩色轮廓。
What even weirder is that if I change .click to .hover it works fine: 更奇怪的是,如果我将.click更改为.hover,它将可以正常工作:
$("#ctamenu ul li ul li").hover(
function () {
$(this).find('.thirdsub').stop().show(300);
},
function () {
$(this).find('.thirdsub').stop().hide(300);
}
);
Would anyone know why this could be working with hover but not click? 有人知道为什么这可以与悬停一起工作但不能单击吗?
$("#ctamenu ul li ul li").click(function (e) {
$(this).find('.thirdsub').stop().show(300);
e.stopPropagation();
});
Try stopPropagation()
because you also have assigned click
handler to parent of that. 请尝试
stopPropagation()
因为您还已将click
handler分配给了它的父对象。 Which will invoke also when you click on #ctamenu ul li ul li
. 当您单击
#ctamenu ul li ul li
时,它也会调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.