How can I style even and odd elements?

后端 未结 9 2066
离开以前
离开以前 2020-11-22 10:44

Is it possible to use CSS pseudo-classes to select even and odd instances of list items?

I\'d expect the following to produce a list of alternating colors, but inste

9条回答
  •  遇见更好的自我
    2020-11-22 11:02

         
    $(document).ready(function(){
          var a=0;
          var ac;
          var ac2;
            $(".names li").click(function(){
               var b=0;
                if(a==0)
                {
                  var accc="#"+ac2;
         if(ac=='part2')
         {
        $(accc).css({
    
        "background": "#322f28",
        "color":"#fff",
        });
         }
         if(ac=='part1')
         {
    
          $(accc).css({
    
          "background": "#3e3b34",
          "color":"#fff",
        });
         }
    
                  $(this).css({
                    "background":"#d3b730",
                    "color":"#000",
                });
                  ac=$(this).attr('class');
                  ac2=$(this).attr('id');
        a=1;
                }
                else{
    
        var accc="#"+ac2;
        //alert(accc);
         if(ac=='part2')
         {
        $(accc).css({
    
        "background": "#322f28",
        "color":"#fff",
        });
         }
         if(ac=='part1')
         {
    
          $(accc).css({
    
          "background": "#3e3b34",
          "color":"#fff",
        });
         }
    
         a=0;
        ac=$(this).attr('class');
        ac2=$(this).attr('id');
        $(this).css({
                    "background":"#d3b730",
                    "color":"#000",
                });
    
                }
    
            });
    

提交回复
热议问题