JQ计较简单
获取第一个元素 $("ul li:first"); $("ul li").eq(0); $("ul li").first(); //获取最后一个: $('ul li').last();
倒数第一个ul,第二个ul,第一个ul样式
$("div ul").eq(-1)$("div ul").eq(-2)
$(
'ul li:first-child'
).css(
'backgroundColor'
,
'#000'
);
JS
$("input[name=Fruit]:eq(0)").attr("checked",true); 名字name叫Fruit的input对象 添加打钩
https://blog.csdn.net/qq_39626986/article/details/80663337
<script type="text/javascript">
$(function(){
$("#title ul li").each(function(index){
$(this).click(function(){
$("#title .titsh").removeClass("titsh");
$("#content .consh").removeClass("consh");
$(this).addClass("titsh");
$("#content > div:eq("+index+")").addClass("consh");
})
})
})
</script>
https://www.cnblogs.com/weihengblogs/p/3961616.html
https://blog.csdn.net/tangxiujiang/article/details/77934459
JS实现隔行变色https://blog.csdn.net/lanseguhui/article/details/80864758 这个太麻烦了
$("#tablelist tr:odd").css("background-color","#ececec"); 在诸如 tr li 这种后面
odd奇数 even偶数
注意是从0算起的
但我们有时候用到css
ul li:first-child
ul 下 第一个 li
ul 下 第2个 li
ul 下 最后一个 li
ul#headuser li{float: left;height: 40px;margin-right: 1px;} #headuser li:first-child{ border: 1px solid black; } #headuser li:nth-child(2){ border-top: 1px solid black; border-bottom:1px solid black; } #headuser li:last-child{ border: 1px solid black; }
ul中最后一个li不加样式
ul li:not(:last-child)
css奇数偶数
#Ulist li:nth-of-type(odd){ margin-left: 20px;}奇数行
#Ulist li:nth-of-type(even){margin-left: 10px;}偶数行
待完善。。