在js中制作一个十行十列的表格,要求每个单元格随机变色
1个回答
2015-11-12
展开全部
onload = function(){
var tab = document.createElement("table");
tab.style.margin = "0 auto";
tab.style.width = "500px";
var tb = document.createElement("tbody");
tab.appendChild(tb);
for(var i = 0; i < 10; i++){
var row = tb.insertRow(tb.rows.length);
for(var j = 0; j < 10; j++){
var col = row.insertCell(row.cells.length);
col.style.width = "50px";
col.style.height = "50px";
var a = Math.floor(Math.random() * 255);
var b = Math.floor(Math.random() * 255);
var c = Math.floor(Math.random() * 255);
col.style.backgroundColor = "rgb(" + a + "," + b + "," + c + ")";
}
}
document.body.appendChild(tab);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询