<html>
<body>
<div id='po'>
<br><input type=text value=1><input type=button value='delete' onclick="aa()">
</div>
<script>
function aa()
{
debugger;
var i = 0;
while(i < po.childNodes.length)
{
po.removeChild(po.childNodes[i]);
i=0;
}
}
</script>
</body>
</html>
<body>
<div id='po'>
<br><input type=text value=1><input type=button value='delete' onclick="aa()">
</div>
<script>
function aa()
{
debugger;
var i = 0;
while(i < po.childNodes.length)
{
po.removeChild(po.childNodes[i]);
i=0;
}
}
</script>
</body>
</html>
能不能再具体一点?
to kingdomzhf()
你的方法是将所有的都去掉了,是不行的。:)function del(q)
{
a=document.getElementsByTagName("br");
if(q<i)
{a[q].removeNode(a[q]);}
else{a[i].removeNode(a[i]);}
}
我写的是点增加按钮就增加一行元素(包括有删除按钮)和一个<br>(i是总行数),然后我点这一行的删除按钮,就删除该行的所有元素以及<br>,但是我上面的方法可能有毛病,在某些情况下出错,删除的不是该行的<br>,请各位高手帮忙,先谢了!
try:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>表格增删</title>
</head>
<body>
<script>
function addrow(){
var r=t.insertRow()
for(i=0;i<t.rows[0].cells.length;i++)r.insertCell().innerHTML=' ';
r.cells[i-1].innerHTML="<input type=checkbox name=c>"
}
function delrow(){
var ch=document.getElementsByName("c")
for(i=ch.length-1;i>=0;i--)if(ch[i].checked)t.deleteRow(ch[i].parentElement.parentElement.rowIndex)
}
</script>
<table border="1" width="300" id=t>
<thead>
<tr>
<th width=120>字段1</th>
<th width=120>字段2</th>
<th>删除</th>
</tr>
</thead>
<tbody>
<tr>
<td>100</td>
<td>200</td>
<td><input type=checkbox name=c></td>
</tr>
</tbody>
</table>
<input type=button value="add" onclick="addrow()"><input type=button value="del" onclick="delrow()">
</body></html>
但是到底能不能够删除<br>呢?