js定数创建表格

 

<!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>
<title>

</title>
<script language="javascript" type="text/javascript">
function add(){
var table=document.createElement("table");
table.setAttribute("border","1px");
table.setAttribute("border","solid");
table.setAttribute("borderColor","blue");
table.setAttribute("bgcolor","#3399FF");
table.setAttribute("width","500px");
table.setAttribute("height","200px");
var lie=document.getElementById("lie").value;
var hang=document.getElementById("hang").value;
for(var i=0;i<hang;i++){
var tr=document.createElement("tr");
for(var j=0;j<lie;j++){
var td=document.createElement("td");


tr.appendChild(td);
table.appendChild(tr);

}


}
div1.appendChild(table);
}
</script>

 

 

</head>
<body>
行数:<input id="hang" type="text" /><p>
列数:<input id="lie" type="text" /><p>

<input  type="button" value="实现" onclick="add()"/>
<div id="div1" style="background-color:#00FFCC; width:200px; height:200px"> </div>

 

</body>

 

 

 


</html>

posted @ 2012-03-04 17:47  Java EE  阅读(200)  评论(0编辑  收藏  举报