问题:希望ul的li奇数行显示灰色,表格table的偶数行tr显示灰色
解决:使用css3的nth-child()选择器或使用jquery
方法:
li:nth-child(odd){ background-color:#ccc; }
tr:nth-child(even) { background: #ccc; }
使用jquery方法
$("li:even").css({ background: #ccc; });
$("tr:odd").css({ background: #ccc; });
注:
因为jquery查找元素是按索引来查的,而索引是从0开始的,所以奇数行是偶数索引
csss3没有这问题