主题:请教一个关于动态增长表格的问题。。。
<!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>Untitled Page</title>
<script language = "javascript" type = "text/javascript">
<!--
function addRow()
{
var table = document.getElementById('table');
if (!table)
{
return false;
}
var tr = document.createElement("tr");
var td = document.createElement("td");
td.appendChild(document.createTextNode("AAA"));
tr.appendChild(td);
td = document.createElement("td");
td.appendChild(document.createTextNode("BBB"));
tr.appendChild(td);
table.appendChild(tr);
return true;
}
//-->
</script>
</head>
<body>
<input type = "button" value = "添加" onclick = "addRow();" />
<table id = "table">
<tr>
<td>列一</td>
<td>列二</td>
</tr>
</table>
</body>
</html>
这个代码在Opera和Firefox中运行不报错,也可以实现所需要的功能。
在IE6里面也不报错,却无法添加新行。
我在哪里写错了呢?
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script language = "javascript" type = "text/javascript">
<!--
function addRow()
{
var table = document.getElementById('table');
if (!table)
{
return false;
}
var tr = document.createElement("tr");
var td = document.createElement("td");
td.appendChild(document.createTextNode("AAA"));
tr.appendChild(td);
td = document.createElement("td");
td.appendChild(document.createTextNode("BBB"));
tr.appendChild(td);
table.appendChild(tr);
return true;
}
//-->
</script>
</head>
<body>
<input type = "button" value = "添加" onclick = "addRow();" />
<table id = "table">
<tr>
<td>列一</td>
<td>列二</td>
</tr>
</table>
</body>
</html>
这个代码在Opera和Firefox中运行不报错,也可以实现所需要的功能。
在IE6里面也不报错,却无法添加新行。
我在哪里写错了呢?