简体   繁体   English

如何再次触发点击事件

[英]How to trigger click event after another click

I have a wordpress mobile navigation where all item collapse (which has 2nd level) when i open the menu .I need to open the about-us section when the menu open. 我有一个wordpress移动导航,当我打开菜单时,所有项目都会折叠(具有第二级)。当菜单打开时,我需要打开“关于我们”部分。 So I try this code but no luck . 所以我尝试了这段代码,但是没有运气。 the .w-nav-control is the menu controller class. .w-nav-control是菜单控制器类。 Please help me what I'm doing wrong? 请帮助我我做错了什么?

jQuery(function($) {
   $(document).on('click', '.w-nav-control', function(event) { 
     event.preventDefault(); 
      setTimeout(function() {
        $('.autoopen').find('span.w-nav-arrow').trigger('click');
        }, 800);
   });
});

It's difficult to troubleshoot this without a jsfiddle, but here's how I'd approach the problem. 没有jsfiddle很难解决这个问题,但是这就是我要解决的问题。 You have essentially two points of failure for your code: the click capture and the click trigger. 您的代码实际上有两点故障:单击捕获和单击触发器。 First, I'd make sure the click event is being triggered with this code: 首先,我将确保使用以下代码触发click事件:

jQuery(function($) {
   $(document).on('click', '.w-nav-control', function(event) { 
     event.preventDefault(); 
     alert('clicked');
   });
});

If that works, you know the problem lies in your click trigger code. 如果可行,您知道问题出在点击触发代码上。 Perhaps try a more specific selector: 也许尝试一个更具体的选择器:

$('#menu-item-5897').find('span.w-nav-arrow').trigger('click');

or perhaps: 也许:

$('#menu-item-5897 > .w-nav-anchor > .w-nav-arrow').trigger('click');

or maybe: 或者可能:

$('.autoopen > .w-nav-anchor > .w-nav-arrow').trigger('click');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM