<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title> new document </title>
<meta name="keywords" content="">
<meta name="description" content="">
<script type="text/javascript" src="js/jq.js"></script>
</head>
<body>
<div id="libox">
 <ul style="list-style:none; line-height:16px; float:left; padding:0px; margin:0px;width:100%" id="brandLiId">
<li>笔记本</li>
<li>手机</li>
<li>鞋子</li>
<li>运动</li>
</ul>
</div>
<script type="text/javascript">
<!--
$("#brandLiId li").hover(function(){$(this).css("background-color","red")},function(){$(this).css("background-color","white")})
//-->
</script>
</body>
</html>现在的html基本是这样,在鼠标经过li列表的时候,背景色变了,鼠标离开时,背景色回到了白色。然后我希望,在点了LI列表后,在离开时,背景色就不回到白色,怎么实现呢?

解决方案 »

  1.   


     $("#brandLiId li").mouseover(function(){
             $(this).css("background-color", "red");
            }); 
      

  2.   

    $("#brandLiId li").hover(function(){$(this).css("background-color","red})
      

  3.   

    $("#brandLiId li").hover(function(){$(this).css("background-color","red)})
      

  4.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=gb2312">
    <title> new document </title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <script type="text/javascript" src="js/jq.js"></script>
    </head>
    <body>
    <div id="libox">
     <ul style="list-style:none; line-height:16px; float:left; padding:0px; margin:0px;width:100%" id="brandLiId">
    <li>笔记本</li>
    <li>手机</li>
    <li>鞋子</li>
    <li>运动</li>
    </ul>
    </div>
    <script type="text/javascript">
    <!--
    $($("#brandLiId li").bind("mouseover",function(){$(this).css("background-color","red")}))
    //-->
    </script>
    </body>
    </html>
      

  5.   

    楼上的应该改成
     $("#brandLiId li").click(function(){
             $(this).css("background-color", "red");
            }); 
    楼主的意思是点击了之后不再变化
      

  6.   


       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=gb2312">
    <title> new document </title>
    <script type="text/javascript" src="jquery-1.4.4.js"></script>
    <script type="text/javascript">
    $(function(){
       $("#brandLiId li").hover(function(){
           $(this).css("background-color","red");
     },function(){
       $(this).css("background-color","white");
     });
       
       $("#test").click(function(){
          $(this).css("background-color","red");
      $("#brandLiId li").unbind("mouseout");
       });
    })</script>
    </head>
    <body>
    <div id="libox">
     <ul style="list-style:none; line-height:16px; float:left; padding:0px; margin:0px;width:100%" id="brandLiId">
    <li>笔记本</li>
    <li>手机</li>
    <li>鞋子</li>
    <li>运动</li>
    <li id="test">test</li>
    </ul>
    </div></body>
    </html>
    点击test时,背景色变,鼠标移开后,背景色不变