Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Can';不对焦_Jquery_Wordpress_Focus - Fatal编程技术网

Jquery Can';不对焦

Jquery Can';不对焦,jquery,wordpress,focus,Jquery,Wordpress,Focus,我试图在搜索字段中设置焦点,当使用上述代码在移动版菜单上单击搜索图标时,我看不出它为什么不工作 如果我将.focus改为.hide,它的效果就像符咒一样,所以选择器看起来都是正确的 非常感谢您的帮助。触发事件的代码在哪里?您是否有id为mega-menu-item-11195的元素?如果是这样,它应该会起作用。大概是这样的: jQuery(function($) { $('#mega-menu-item-11195').on('open_panel', function() {

我试图在搜索字段中设置焦点,当使用上述代码在移动版菜单上单击搜索图标时,我看不出它为什么不工作

如果我将.focus改为.hide,它的效果就像符咒一样,所以选择器看起来都是正确的


非常感谢您的帮助。

触发事件的代码在哪里?您是否有id为
mega-menu-item-11195
的元素?如果是这样,它应该会起作用。大概是这样的:

jQuery(function($) {
    $('#mega-menu-item-11195').on('open_panel', function() { 
       $('#woocommerce-product-search-field-0').focus();
    });
});

我相信这是一个演示您正在寻找的行为的示例。

mega-menu-item-11195
是菜单中的列表项。我不确定触发它的代码在哪里,这是Max Mega菜单插件的一部分!如果我更改
$('#woocommerce-product-search-field-0')。focus(),面板的打开状态非常好
$('#woocommerce-product-search-field-0')。隐藏()后者工作正常,因此与焦点有关(我没有使用开发控制台)
jQuery(function($) {
    $('#openButton').click(function() {
    $('#mega-menu-item-11195').trigger('open_panel');
  });

  $('#mega-menu-item-11195').on('open_panel', function() { 
     $('#woocommerce-product-search-field-0').focus();
  });
});