<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
<link href="css/mobile.css" rel="stylesheet" />
<title>test</title>
<script type="text/javascript" src="js/app.js"></script></head>
<style type="text/css">
.test li{margin-bottom:10px}
.one{background:#f00;}
.two{background:#000;color:#fff;font-weight:bold;}
</style>
<body>
<div class="test">
    <ul>
        <li class="one">AAAAAAAAAAA</li>
        <li class="one">AAAAAAAAAAA</li>
        <li class="one">AAAAAAAAAAA</li>
        <li class="one">AAAAAAAAAAA</li>
    </ul>
</div><script type="text/javascript">
$(function(){

$(".test").bind("click",function(e){
        e = e || window.event;
        var tar = e.srcElement || e.target;
        if(tar.nodeName.toLowerCase() == "li" && !$(tar).hasClass('two')){
            $(tar).addClass("two");
            $(tar).siblings().removeClass("two");
        }else{
            $(tar).removeClass("two");
        }
    })
})</script>
</body>
</html>

解决方案 »

  1.   

    jquery里面有个toggle,很适合你这种情况,可以参考我写的:
      $(function(){
           $("li").toggle(
                function(){
                    $(this).removeClass("one");
                    $(this).addClass("two");
                },
                function(){
                    $(this).removeClass("two");
                    $(this).addClass("one");
                }
                )
            })
      

  2.   

      $(function(){        
             $("li").toggle(             
                       function(){                 
                                 $(this).removeClass("one").addClass('two').siblings().removeClass("two").addClass("one"); 
                                         },             
                       function(){                 
                               $(this).removeClass("two").addClass("one").siblings().removeClass("one").addClass("two");                 
                                         
    }             
    )         
    }