1

如何让li标签在鼠标悬停时单独亮起所有li标签同时亮起

 $(document).ready(function(){
  $("li").mouseover(function(){
   $("li").css("background-color","yellow");
 });
  $("li").mouseout(function(){
  $("li").css("background-color","lightgray");
  });
});

HTML:

 <ul class="menu">
 <li>Bookmarks</li>
 <li>Something</li>
 <li>BUMPER STICKERS</li>
 <li>CARBONLESS FORMS</li>
 <li>CD JACKETS</li>
 <li>DIE CUT/CUSTOM STICKERS</li>
 <li>DOOR HANGERS</li>
 <li>ENVELOPES</li>
 <li>FOLDERS</li>
 <li>LETTERHEADS</li>
 <li>RECTANGULAR STICKERS</li>
 <li>ROUND STICKERS</li>
 <li>STATIC CLING </li>
 <li>TABLE TENTS</li>
 <li>VINYL BANNERS</li>
<li>WINDOW STICKERS</li>

</ul>
4

4 回答 4

1

演示:http: //jsfiddle.net/whZYD/

 $(document).ready(function(){
  $("li").mouseover(function(){
   $(this).css("background-color","yellow");
 });
  $("li").mouseout(function(){
  $(this).css("background-color","lightgray");
  });
});
于 2013-03-01T05:59:51.370 回答
1

为什么不直接使用 CSS?

li {
    background-color: lightgray;
}

li:hover {
    background-color: yellow;
}
于 2013-03-01T06:01:17.243 回答
1

尝试:

$(document).ready(function () {
 $("li").hover(function () {
     $(this).css("background-color", "yellow");
 }, function () {
     $(this).css("background-color", "lightgray");
 });
});

或者干脆使用 Css:

li {
  background-color: lightgray;
}

li:hover {
  background-color: yellow;
}
于 2013-03-01T06:02:33.737 回答
1

代码:

    #page li:hover a:visited
    {
    background-color:green;
    } 

看看下面的链接:

li:hover 访问过的颜色

http://htmlbook.ru/css/hover

于 2013-03-01T06:08:48.037 回答