参考如下代码:
<html>
<head> <title>Test javascript method </title>
<script language="javascript">
var addTr = new function() {
this.addFun = function() {
var tableName = document.getElementById("mytable");
var thChar = tableName.insertRow(-1); var tdorder = thChar.insertCell(-1);
var tdname = thChar.insertCell(-1);
var tdtel = thChar.insertCell(-1); tdorder.appendChild(document.createTextNode("1"));
tdname.appendChild(document.createTextNode("star"));
tdtel.appendChild(document.createTextNode("13880074647"));
}
}
window.onload = addTr.addFun;
</script>
<body><table id="mytable" border="1">
<tr>
<th>order </th>
<th>name </th>
<th>telephone </th>
</tr>
</table></body>
<html>
<head> <title>Test javascript method </title>
<script language="javascript">
var addTr = new function() {
this.addFun = function() {
var tableName = document.getElementById("mytable");
var thChar = tableName.insertRow(-1); var tdorder = thChar.insertCell(-1);
var tdname = thChar.insertCell(-1);
var tdtel = thChar.insertCell(-1); tdorder.appendChild(document.createTextNode("1"));
tdname.appendChild(document.createTextNode("star"));
tdtel.appendChild(document.createTextNode("13880074647"));
}
}
window.onload = addTr.addFun;
</script>
<body><table id="mytable" border="1">
<tr>
<th>order </th>
<th>name </th>
<th>telephone </th>
</tr>
</table></body>
你说的这种方式我会
现在我就是想知道为什么在firefox下能正常运行上面的javascript,在IE下不行。
alert(tableName.outerHTML);
tby.appendChild(thChar);