日期:2014-05-16  浏览次数:20382 次

为什么不能创建表格?
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN ">
<html>
<head>
<title> </title>
<meta   name= "GENERATOR "   content= "Microsoft   Visual   Studio   .NET   7.1 ">
<meta   name= "ProgId "   content= "VisualStudio.HTML ">
<meta   name= "Originator "   content= "Microsoft   Visual   Studio   .NET   7.1 ">
<style   type= "text/css ">
div{position:absolute;   left:100px;   top:100px;   width:300px;   height:500px;background-color:yellow;}
</style>
<script   language= "javascript ">
function   draw()
{
var   r   =   document.getElementById( "txtRow ");
var   c   =   document.getElementById( "txtColumn ");
if(r.value== " "||c.value== " ")
return;
else
{
var   rc   =   parseInt(r.value);
var   cc   =   parseInt(c.value);
var   tab   =   document.createElement( "table ");
tab.style.border   =   1;
for(var   i=0;i <rc;i++)
{
var   row   =   document.createElement( "tr ");
for(var   j=0;j <cc;j++)
{
var   td   =   document.createElement( "td ");
td.innerHTML   =   "Row: "   +   i   +   "   "   +   "Col "   +   j;
row.appendChild(td);
}
tab.appendChild(row);
}

document.getElementById( "d ").appendChild(tab);
}
}
</script>
</head>
<body>
<form>
Row <input   type= "text "   id= "txtRow "> <br>
Column <input   type= "text "   id= "txtColumn "> <br>
<input   type= "button "   value= "Create   Table "   onclick= "draw(); ">
<div   id= "d "> </div>
</form>
</body>
</html>


------解决方案--------------------
LZ不要费力了
IE中不能用DOM3的方法创建TABLE只能用DOM1的方法
在FF中可能可以
------解决方案--------------------
可以这样
document.getElementById( "mytable ").parentElement.innerHTML = " <table> <tr> " + getCol() + " </tr> </table> ";

To change the contents of the table, tFoot, tHead, and tr elements, use the table object model described in How to Build Tables Dynamically. For example, use the rowIndex property or the rows collection to retrieve a reference to a specific table row. You can add or delete rows using the insertRow and deleteRow methods. To retrieve a reference to a specific cell, use the cellIndex property or the cells collection. You can add or delete rows using the insertCell and deleteCell methods. To change the content of a particular cell, use the innerHTML property.