时间:2021-07-01 10:21:17 帮助过:16人阅读
本文实例为大家分享了js实现隔行变色的具体代码,供大家参考,具体内容如下
<script type="text/javascript">
function createTable(){
//创建表格
var table = document.createElement("table");
//设置表格的行数
for(var i=0;i<4;i++){
var tr = document.createElement("tr");
//设置表格的列数
for( var j=0;j<5;j++){
var td = document.createElement("td");
tr.appendChild(td);
//添加文本
var txt = document.createTextNode("wkk");
td.appendChild(txt);
}
//判断颜色的变换
if(i%2==0){
//添加属性(第一种)
tr.style.backgroundColor = "#f0f";
} else {
tr.style.backgroundColor = "#ff0";
}
table.appendChild(tr);
}
//添加属性(第二种)
table.setAttribute("border","1px");
//table.style.border = "solid 1px red";
table.setAttribute("width","200px");
table.setAttribute("height","100px");
//添加到body中
document.body.appendChild(table);
}//create table over
createTable();
</script>上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
在JavaScript中有哪些特殊数据类型
在微信小程序中如何使用request网络进行请求操作
使用NodeJS编写爬虫示例
在Angular中使用MathJax碰到哪些问题?
在ReactNative中如何使用Redux架构
在javascript中如何实现显式转换与隐式转换
以上就是使用js如何实现隔行变色的详细内容,更多请关注Gxl网其它相关文章!