使用jQuery更改li的背景颜色

问题描述:

我想在鼠标悬停时更改包含锚点的li的颜色,我这样做

I want to change the color of li which contains anchor when the mouse go over it, I make like this

 <ul id="SonsItemList">
     <li class="sonItem"><a id="son" href="#" >son 1</a></li>
      <li class="sonItem"><a id="son" href="#" >son 2</a></li>        
 </ul>

jquery是

 $(document).ready(function(){
            $("a#son").hover(function(){
               $("li.sonItem").css("background-color","black");  // it make all li background => black


        });

我只想让慕斯走过去改变背景,我该怎么做? });

I just want the li that the mous go over to change it's background, how can I make it ? });

您根本不需要任何JavaScript.您可以使用CSS:

You don't need any JavaScript at all. You can use CSS:

li.sonItem:hover 
{
    background-color: black;
}