这次给大家带来js怎么实现隔行变色,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>相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上就是js怎么实现隔行变色的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号