Web表格部分内容

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 str='<table border="1"><tr><td>Bill Gates</td></tr></table>';


function init(row, col)
{
var myArray=new Array(13);//存储单元格的元素值
var n= (row*col)/2 ;
for(var k=1;k<=n;k++)
{
myArray[k]= parseInt( Math.random() *n );
myArray[(k+n)]=myArray[k];
}


var str='<table border="1" width="300" height="300">';
for(var i=1;i<=row;i++)
{
str+="<tr>";
for(var j=1;j<=col;j++)
{
str+="<td onclick='judge("+ ( (i-1)*col+j )+");'>"+ myArray[ ((i-1)*col+j) ] +"</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)
{
alert(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>

posted on 2016-03-24 19:33  自画何用费笔墨  阅读(94)  评论(0编辑  收藏  举报

导航