今天做了表单,还做了单双行分颜色。
var arr = [ ["周更生","男",30,true,"大专",5000,500,,"山东省"], ["刘晓庆","女",26,false,"研究生",8000,1500,"北京科技大学","山西省"], ["习近","男",38,true,"大专",1000,250,"清华大学","陕西省"], ["克强","女",34,true,"高中",11000,30,"河北大学","江苏省"], ]; var arr_length=arr.length; //定义一个tablbe var str="<table width=‘600‘ border=‘1px‘ align=‘center‘ style=‘border-collapse:collapse‘;>"; str+="<caption><h2>学生信息表</h2></caption>"; for(var i=0;i<arr_length;i++) { str+="<tr"; if(i%2==0){ str+=" bgColor=‘red‘"; } str+=">" //分部单行加颜色 // if(i%2==0){ // str+="<tr bgColor=‘red‘>"; // }else{ // str+="<tr>"; // } // str+="<tr"; // if(i%2==0){ // str+=" bgColor=‘red‘"; // } // str+=">" for(var j=0;j<arr[i].length;j++){ str+="<td>"+arr[i][j]+"</td>"; } str+="</tr>"; } str+="</table>"; document.write(str);
时间: 2024-12-20 20:23:01