每周一结,这周是动态表格
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>活动表格</title> <script type="text/javascript">
var myArray=new Array(13);
function mySort() { return Math.random()>.5; }
function init(row, col) {
//0--12 for(var k=0;k<6;k++) { myArray[k]=( Math.round( Math.random()*5 )+1); myArray[k+6]=myArray[k]; } myArray.sort(mySort);
var str='<table name="myT" border="1" width="300" height="300">'; for(var i=1;i<=row;i++) { str+="<tr>"; for(var j=0;j<col;j++) { str+="<td οnclick='judge("+ ((i-1)*col +j )+");'>" str +="<img id='img_"+ ((i-1)*col +j )+"' src='photo/image0.gif'/>" str+="</td>"; } str+="</tr>"; } str+= "</table>" // i=1 j=1---3 1 2 3 (i-1)*3+j //i=2 4 5 6 //document.write(str); document.getElementById("mt").innerHTML=str; } function createTable() { var row=document.getElementById("t1").value; var col=document.getElementById("t2").value; init(row,col); } function judge(temp) { //temp 表格单元格编号 1---12
var currImg=document.getElementById("img_"+temp); currImg.src="photo/image"+myArray[temp]+".gif"; alert(myArray[temp]); } </script> </head>
<body> <div id="mt">test</div> <input type="text" value="3" id="t1"/> <input type="text" value="4" id="t2"/> <input type="button" value="生产表格" onClick="createTable();"/> </body> </html>