本帖最后由 Myprettygirl 于 2013-06-09 09:45:50 编辑

解决方案 »

  1.   

    <script type="text/javascript">
        //点击当前的a添加on类,并给其他a清除类名
        $("#getcolor li a").click(function(){
            $(this).addClass("on").parent().siblings().find("a").removeAttr("class");
        })
    </script>
      

  2.   

    $("#getcolor li").click(function(){
        $(this).children("a").addClass("class1").parent().siblings().find("a").removeClass("class1");
    });
      

  3.   


    另外this.getElementsByTagName("a")[0].innerHTML这句,在jquery中可替换为$(this).find("a").eq(0).text()
      

  4.   

    因为a是行内替换元素,对其宽度什么不太容易统一控制,还是操作li的样式比较好。$(function() {
    $("ul li").bind("click",function() {
        $(this).addClass("selected").siblings().removeClass("selected");
    });
    });
      

  5.   


    另外this.getElementsByTagName("a")[0].innerHTML这句,在jquery中可替换为$(this).find("a").eq(0).text()
    这样写的话,是直接获取到了a标签吧。那又怎么获取到值呢
        $("#getcolor li a").click(function(){
             alert($(this).find("a").eq(0).text());
           alert($(this).eq(0).text());
            $(this).addClass("on").parent().siblings().find("a").removeAttr("class");
        })
    这两种alert都不行
      

  6.   

    这个又怎么获取到值呢?我用3楼的替换方法这么写,得不到值。这个是直接获取到了a标签吧,那就不用再find了。但是还不行
        $("#getcolor li a").click(function(){
        alert($(this).find("a").eq(0).text());
           alert($(this).eq(0).text());
            $(this).addClass("on").parent().siblings().find("a").removeAttr("class");
        })
      

  7.   


    另外this.getElementsByTagName("a")[0].innerHTML这句,在jquery中可替换为$(this).find("a").eq(0).text()不好意思,是我搞错了,谢谢二位。已经好了
      

  8.   

    这个又怎么获取到值呢?我用3楼的替换方法这么写,得不到值。这个是直接获取到了a标签吧,那就不用再find了。但是还不行
        $("#getcolor li a").click(function(){
        alert($(this).find("a").eq(0).text());
           alert($(this).eq(0).text());
            $(this).addClass("on").parent().siblings().find("a").removeAttr("class");
        })
    直接$(this).text()就是a里的值了