<body>
行数:<input type="text" id="row"/><br />
列数:<input type="text" id="col"/><br />
宽度:<input type="text" id="width"/><br />
高度:<input type="text" id="height"/><br /><input type="button" id="click" value="生成表格" onclick="diaoyong()"/><table align="center"><tr><td colspan=""></td></tr></table><script>
function diaoyong(){
var row = document.getElementById("row").value;
var col = document.getElementById("col").value;
var width = document.getElementById("width").value;
var height = document.getElementById("height").value;
var table =newTable(row, col, width, height);
var show = table.run();
document.write(show);}
function Table(row, col, width, height){this.row = row;this.col = col;this.width = width;this.height = height;this.run = shengcheng;}
function shengcheng(){
var show =""
var color =""
show +=("<table width='"+this.width +"px' height='"+this.height +"px' align="+'center'+">");for(var i =0; i <this.row; i++){switch((i+1)%7){case1:
color ="red";break;case2:
color ="orange";break;case3:
color ="yellow";break;case4:
color ="green";break;case5:
color ="cyan";break;case6:
color ="blue";break;default:
color ="purple";
count =0;}
show +=("<tr bgcolor = '"+ color +"'>")for(var y =0; y <this.col; y++){if(y ==0){
show +=("<td >")
show +=("</td>")}else{
show +=("<td>")
show +=("</td>")}}
show +=("</tr>")}
show +=("</table>");return show;}</script></body>