使用子菜单单击菜单项将在移动设备上打开所有其他子菜单
在下面使用的jQuery函数添加功能以滑动菜单项的子菜单,该子菜单为移动视口提供了孩子。
$('.submenu-open').click(function(e) {
$('.menu-item-has-children li').slideToggle('slow');
});
但是,它同时(在移动视口上)与孩子一起打开所有菜单项,但它只能打开该菜单项的子菜单。
这是 link
used below jquery function to add functionality to slide toggle the submenu of the menu items which has got children for the mobile viewport.
$('.submenu-open').click(function(e) {
$('.menu-item-has-children li').slideToggle('slow');
});
But, it opens all the menu items with children at the same time (on mobile viewport), But it should only open the submenu of that menu item.
here is the link
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然这可能不是确切的解决方案,但更多的是您需要的线路。
Vanilla JS,没有JQuery:
您的问题是,您并不是只将类添加到单击元素中,而是所有这些元素。
While this may not be the exact solution, it is more on the line of what you need.
Vanilla JS, without JQuery:
Your problem ist, that you aren't adding the class to only the clicked element, but all of them.
在“单击事件”侦听器的回调函数中,您必须使用jQuery的
$(this)
对象首先关闭目标。发生。然后使用方法
childror()
在该对象上以针对相关的对象无序列表.sub-menu
:Within the click event listener's callback function, you have to use jQuery's
$(this)
object to first off target the very.menu-item-has-children
where the click event occurred.Then use the method
children()
on that object to target the related unordered list.sub-menu
: