Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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
Javascript Jquery选择器与下拉列表有关_Javascript_Jquery - Fatal编程技术网

Javascript Jquery选择器与下拉列表有关

Javascript Jquery选择器与下拉列表有关,javascript,jquery,Javascript,Jquery,我有下拉菜单。在顶层中,项目的背景图像(胡萝卜指示器)应用于鼠标悬停时的href标记。当光标位于子菜单项上时,我希望在父li href项上保留或重置相同的背景图像。我是jQuery的新手,请帮忙 我厌倦了跟随,但显然不知道我在做什么 $('ul.sub-menu').parent('li a').hover( function() { $(this).css('background-image','/wp-content/themes/wp-crumblemagazine/image

我有下拉菜单。在顶层中,项目的背景图像(胡萝卜指示器)应用于鼠标悬停时的href标记。当光标位于子菜单项上时,我希望在父li href项上保留或重置相同的背景图像。我是jQuery的新手,请帮忙

我厌倦了跟随,但显然不知道我在做什么

$('ul.sub-menu').parent('li a').hover(
  function() {
    $(this).css('background-image','/wp-content/themes/wp-crumblemagazine/images    /bg/carrot.gif');
  }, function() {
$(this).css('background-image','none');
  });
   });
});
这是该页面的url


首先,您的选择器没有返回任何对象,因此可能是错误的……其次,我不会让箭头在进入子菜单时消失。 +您还需要定位背景图像,而不仅仅是启用它

但是。。。下面是带有颜色的示例

jQuery('ul.sub-menu').parent().find('li>a').hover( function(){
    jQuery(this).parent().parent().parent().find("a.sf-with-ul").css('color','red');
},
function(){
    jQuery(this).parent().parent().parent().find("a.sf-with-ul").css('color','white');
}
);