我正在使用Bootstrap下拉菜单。请参阅以下代码:
$(document).ready(function(){
$("#a-primary-occasion").mouseover(function(){
$(".dropdown-menu_occasion").css("display", "block");
});
$('#submenu-birthday_occasion').mouseover();
});
此脚本位于主菜单的phtml文件中,可在加载页面时正常工作。但是点击外部菜单(在页面的其他内容上)后,它不会触发mouseover()
事件。
您可以在此处查看:http://jshri.com
加载页面后,只需将鼠标悬停在第一个菜单(场合)上。它将打开“生日礼物”的子菜单。
点击菜单外的任何地方(例如“场合”菜单上方)
将鼠标悬停在Occasion菜单上,它将无法打开第一个菜单。还会徘徊在第一个子菜单(即生日礼物)上。但是在徘徊在第二个子菜单(即周年纪念礼物)之后,即使第一个子菜单也能正常工作,也会打开子菜单。
注意:如果我在document.ready()
中添加提醒,则每次都会触发。
我不确定为什么会这样。有谁有想法吗?我该如何解决这个问题?
答案 0 :(得分:0)
我自己找到了!
正如我所说我正在使用Bootstrap菜单,默认菜单是在点击事件上打开的。我把它改成了悬停事件。但我没有删除隐藏在document.click
事件上当前打开的菜单的jQuery。这是我评论的代码:
$(document).click(function() {
// Simply hide the submenu on any click. Again, this is just a hacked
// together menu/submenu structure to show the use of jQuery-menu-aim.
$(".popover_relation").css("display", "none");
$("a.maintainHover_relation").removeClass("maintainHover_relation");
});