如何移除指定id的内容?
以下span是由js生成的:
document.getElementById( "filelist ").insertAdjacentHTML( "beforeEnd ", ' <span id= "f_0 "> <a href= "./a.aspx?id=1 "> 一行 </a> </span> <span id= "f_0 "> 删除 </span> ');
<div id= "filelist ">
<span id= "f_0 "> <a href= "./a.asp?id=1 "> 一行 </a> </span> <span id= "f_0 "> 删除 </span>
<span id= "f_1 "> <a href= "./a.asp?id=2 "> 一行 </a> </span> <span id= "f_1 "> 删除 </span>
<span id= "f_2 "> <a href= "./a.asp?id=3 "> 一行 </a> </span> <span id= "f_2 "> 删除 </span>
<span id= "f_3 "> <a href= "./a.asp?id=4 "> 一行 </a> </span> <span id= "f_3 "> 删除 </span>
</div>
如何实现,点击“一行”的时候,则将id= "file_0 "的span标签去掉。其它行同理。
------解决方案--------------------LZ 看看行不?
<div id= "filelist ">
<span id= "f_0 "> <a href= "./a.asp?id=1 "> 一行 </a> </span> <span id= "f_0 " onclick= "deleteSpan( 'f_0 '); "> 删除 </span>
<span id= "f_1 "> <a href= "./a.asp?id=2 "> 一行 </a> </span> <span id= "f_1 " onclick= "deleteSpan( 'f_1 '); "> 删除 </span>
<span id= "f_2 "> <a href= "./a.asp?id=3 "> 一行 </a> </span> <span id= "f_2 " onclick= "deleteSpan( 'f_2 '); "> 删除 </span>
<span id= "f_3 "> <a href= "./a.asp?id=4 "> 一行 </a> </span> <span id= "f_3 " onclick= "deleteSpan( 'f_3 '); "> 删除 </span>
</div>
<script language= "JavaScript ">
<!--
function deleteSpan(sId)
{
var oSpan = document.getElementById(sId);
var oParent = oSpan.parentNode;
oParent.removeChild(oSpan);
}
//-->
</script>
------解决方案-------------------- <div id= "filelist ">
<span id= "f_0 "> <a href= "./a.asp?id=1 "> 一行 </a> </span> <span id= "f_0 " onclick= "this.previousSibling.removeNode(true);this.removeNode(true); "> 删除 </span>
<span id= "f_1 "> <a href= "./a.asp?id=2 "> 一行 </a> </span> <span id= "f_1 " onclick= "this.previousSibling.removeNode(true);this.removeNode(true); "> 删除 </span>
<span id= "f_2 "> <a href= "./a.asp?id=3 "> 一行 </a> </span> <span id= "f_2 " onclick= "this.previousSibling.removeNode(true);this.removeNode(true); "> 删除 </span>
<span id= "f_3 "> <a href= "./a.asp?id=4 "> 一行 </a> </span> <span id= "f_3 " onclick= "this.previousSibling.removeNode(true);this.removeNode(true); "> 删除 </span>
</div>
------解决方案--------------------指定id的内容还是指定的元素?
指定的内容
document.getElementById( "指定id ").innerHTML= " "
指定的元素
document.getElementById( "指定id ").parentNode.removeChild(document.getElementBy