0

I can't change my html because this is the hack for me to do something (sorting algo), however it broke my css because I can't use even and odd anymore..

http://jsfiddle.net/Hms7Y/24/

try to add 1 and then follow by 2, it has the same background.. I tried to apply 3 classes for 3 li, doesn't work because there are various behaviour by users.

li:nth-child(even){
background:#DDD;    
}
4

2 回答 2

1

http://jsfiddle.net/kidino/JRwM7/1/

只需使用 :visible 过滤 js 中隐藏的 li

  $('ul li').removeClass('even');
  $('ul li:visible:odd').addClass('even');
于 2013-10-21T03:07:48.807 回答
0

试试这个:小提琴

$(document).ready(function() {
  $('button').click(function() {
    var lvl = $('select').val();

    $('<li class="level" '+ lvl + '>' + lvl + '</li>').appendTo('ul');
  });
});
于 2013-10-20T13:55:43.107 回答