[英]Disabling prevent.Default action
I have a piece of javascript code which initiates mobile menu dropdown.我有一段 javascript 代码,它启动移动菜单下拉菜单。 But while I was working on this, I wasn't paying attention and stupidly copied a code from another source and now I can't click on parent items on mobile menu.但是当我在做这个的时候,我没有注意并愚蠢地从另一个来源复制了一个代码,现在我无法点击移动菜单上的父项。
When I remove e.preventDefault();
当我删除e.preventDefault();
, I'm getting an error in console and menu is not working. ,我在控制台中遇到错误并且菜单不起作用。 Here is the full code.这是完整的代码。 What can I do with my code to make the parent items clickable?我可以用我的代码做什么来使父项可点击?
var $dropdownOpener = $('.mobile-header-navigation .menu-item-has-children > a');
if ($dropdownOpener.length) {
$dropdownOpener.each(function () {
var $thisItem = $(this);
$thisItem.on('tap click', function (e) {
e.preventDefault();
var $thisItemParent = $thisItem.parent(),
$thisItemParentSiblingsWithDrop = $thisItemParent.siblings('.menu-item-has-children');
if ($thisItemParent.hasClass('menu-item-has-children')) {
var $submenu = $thisItemParent.find('ul.sub-menu').first();
if ($submenu.is(':visible')) {
$submenu.slideUp(450);
$thisItemParent.removeClass('qodef--opened');
} else {
$thisItemParent.addClass('qodef--opened');
if ($thisItemParentSiblingsWithDrop.length === 0) {
$thisItemParent.find('.sub-menu').slideUp(400, function () {
$submenu.slideDown(400);
});
} else {
$thisItemParent.siblings().removeClass('qodef--opened').find('.sub-menu').slideUp(400, function () {
$submenu.slideDown(400);
});
}
}
}
});
});
}
}
也许尝试使用空检查调用 e.originalEvent.preventDefault() ,例如:
e && e.originalEvent && e.originalEvent.preventDefault()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.