把创建的表单元素插入的时候可以试试这个函数insertAdjacentElement参考
insertAdjacentElement Method Internet Development Index --------------------------------------------------------------------------------Inserts an element at the specified location.SyntaxoElement = object.insertAdjacentElement(sWhere, oElement)
ParameterssWhere Required. String that specifies where to insert the HTML element, using one of the following values: beforeBegin Inserts oElement immediately before the object.
afterBegin Inserts oElement after the start of the object but before all other content in the object.
beforeEnd Inserts oElement immediately before the end of the object but after all other content in the object.
afterEnd Inserts oElement immediately after the end of the object.
oElement Required. Object that specifies the element to be inserted adjacent to the object that invoked the insertAdjacentElement method. Return ValueReturns an element object.
另外:楼主的速度真是快~`
insertAdjacentElement Method Internet Development Index --------------------------------------------------------------------------------Inserts an element at the specified location.SyntaxoElement = object.insertAdjacentElement(sWhere, oElement)
ParameterssWhere Required. String that specifies where to insert the HTML element, using one of the following values: beforeBegin Inserts oElement immediately before the object.
afterBegin Inserts oElement after the start of the object but before all other content in the object.
beforeEnd Inserts oElement immediately before the end of the object but after all other content in the object.
afterEnd Inserts oElement immediately after the end of the object.
oElement Required. Object that specifies the element to be inserted adjacent to the object that invoked the insertAdjacentElement method. Return ValueReturns an element object.
另外:楼主的速度真是快~`
function fnAdd()
{
var oNewItem = document.createElement("LI");
oList.children(0).insertAdjacentElement("beforeEnd",oNewItem);
oNewItem.innerText = "List Item 0";
}
</SCRIPT>
:
<BODY>
<OL ID = "oList">
<LI>List Item 1</LI>
<LI>List Item 2</LI>
<LI>List Item 3</LI>
</OL>
<INPUT TYPE = "button" VALUE = "Add Item" onclick="fnAdd()">
</BODY>
<head>
<title>Untitled</title>
<Script language="javascript">
<!--
function creates(i){
newTable=document.createElement("TABLE")
newTable.border=i
newTable.align="left"
newTable.style.background="red"
newTable.insertRow()
newTable.rows[0].insertCell();
document.getElementById("table1").insertAdjacentElement("afterEnd",newTable);
}
//-->
</Script>
</head><body onload="creates(1);">
<table id=table1 bgcolor="#009900"><tr><td>123</td></tr></table>
<input type="button" onclick="creates(2);"/>
</body>
</html>
是要这样的吗???
http://community.csdn.net/Expert/topic/4630/4630638.xml?temp=.631817
<body>
<table id=table1><tr><td>123</td></tr></table>
<hr>
</body><SCRIPT LANGUAGE="JavaScript">
var tab = document.createElement("TABLE");
var tr = tab.insertRow(0); //兼容所有浏览器
var td = tr.insertCell(0);
td.innerHTML = "mm";
var old = document.getElementById("table1");
document.body.insertBefore(tab, old.nextSibling);
alert(document.documentElement.innerHTML);
</SCRIPT>