怎样能使html的外部样式表奇偶行交替色类似?

怎样能使html的外部样式表奇偶行交替色类似?,第1张

jQuery中设置html的外部样式表的奇偶行交替色类似:

设置偶数行的背景色:$("table  tr:nth-child(even)").css("background-color","#FFE4C4")

设置奇数行的背景色:$("table  tr:nth-child(odd)").css("background-color","#F0F0F0") 

可以使用css3的奇偶选择器:

tr:nth-child(odd){background-color:#FFE4C4}。

tr:nth-child(even){background-color:#F0F0F0}li:nth-child(odd)是设置奇数行的背景色,li:nth-child(even)是设置偶数行的。

参考资料

jQuery中设置html的外部样式表的奇偶行交替色类似.博客[引用时间2018-1-5]

可以啊,用css3或者jq实现。

可以使用css3的奇偶选择器,如:

tr:nth-child(odd){background-color:#FFE4C4}

tr:nth-child(even){background-color:#F0F0F0}

li:nth-child(odd)是设置奇数行的背景色,li:nth-child(even)是设置偶数行的。但是css3不兼容IE9以下的浏览器,如果需要考虑到兼容问题的话,可以使用jq设置,如:

$("table  tr:nth-child(even)").css("background-color","#FFE4C4")    //设置偶数行的背景色

$("table  tr:nth-child(odd)").css("background-color","#F0F0F0")    //设置奇数行的背景色

<script type="text/javascript">

var count = 0 //循环计数器

var jicount = 0 //奇数计数器

var oucount = 0 //偶数计数器

var arr = new Array() //储存随机数数组

var jishu = new Array() //储存奇数数组

var oushu = new Array() //储存偶数数组

while(count <10){//为奇偶数组赋值

arr[count] = (Math.round((Math.random()*9)+1))

if(arr[count]%2==1){

jishu[jicount] = arr[count]

jicount++

}else{

oushu[oucount] = arr[count]

oucount++

}

count++

}

document.write(jishu.sort(function(a,b){return a-b})) //奇数数组排序输出

document.write("<br />")

document.write(oushu.sort(function(a,b){return a-b})) //偶数数组排序输出

</script>

有一点注释,看不懂再问我。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/6275161.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-19
下一篇 2023-03-19

发表评论

登录后才能评论

评论列表(0条)

保存