<div>sdf
<div style="width:100px;height:100px;background:#EEE" onclick = this.parentNode.removeChild(this)>asfd</div>
</div>

解决方案 »

  1.   


    <div onclick = "this.display='none';"> asfd </div> 
      

  2.   

    大概就这个意思,看看行吗?
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title><style>.box{ width:100px; height:100px; border:1px solid #000; }
    </style>
    </head><body>
    <script language="JavaScript" type="text/javascript">
    <!--
    function createEle(tag){
    var ele = document.createElement(tag);
    ele.className = 'box';
    ele.onclick = function(){
    this.parentNode.removeChild(this);
    }
    ele.innerHTML = '点击就删除了';
    document.body.appendChild(ele);
    }function start(){
    for(var i=0; i<10; i++){
    createEle('div');
    }
    }
    start();
    //-->
    </script></body>
    </html>
      

  3.   

    兼容IE和FF
    <script type="text/javascript">
    function addDiv(value)
    {
      var div = document.createElement("div");
      div.innerHTML = "HelloWorld";
      div.style.border="1px solid black";
      div.style.width="100px";
      div.onclick=deleteDiv;
      document.body.appendChild(div);
    }
    function deleteDiv(event)
    {
      event = event || window.event;
      var div = event.target?event.target:event.srcElement;
      div.parentNode.removeChild(div);
    }
    </script>
    <input type="button" value="AddDiv" onclick="addDiv()" />
      

  4.   

    楼上的大哥。如果我要删除所有DIV的ID前半部分等于“aaa”的应该怎么做了?谢谢
      

  5.   

    <script>
    function deldiv(id){
     if(id.substr(0,3)!="aaa")return
     o = document.getElementById(id)
     o.parentNode.removeChild(o);
    }
    </script>
    <div> sdf 
    <div id="aaa1" style="width:100px;height:100px;background:#EEE" onclick = deldiv(this.id)> asfd</div>
    <div id="waaa1" style="width:100px;height:100px;background:#EEE" onclick = deldiv(this.id)> asfd</div>
    <div id="saaa1" style="width:100px;height:100px;background:#EEE" onclick = deldiv(this.id)> asfd</div>
    <div id="aaa1" style="width:100px;height:100px;background:#EEE" onclick = deldiv(this.id)> asfd</div> 
    </div> 
      

  6.   

    nodeName.parentNode.removeChild(nodeName)
      

  7.   

    <DIV id=er_1205389132578 style="Z-INDEX: 2147483647; FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/er_large.png, sizingmethod=scale);; LEFT: 1787px; WIDTH: 20px; POSITION: absolute; TOP: 1752px; HEIGHT: 34px"></DIV>
    <DIV id=shadow_1205389132578 style="Z-INDEX: 1; FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/er_large_shadow.png, sizingmethod=scale);; LEFT: 1787px; WIDTH: 37px; POSITION: absolute; TOP: 1752px; HEIGHT: 34px"></DIV>为什么我删除这2个div后。过段时间或者鼠标拖动的时候这两个DIV又显示出来了了?
      

  8.   

    在一个overlays中使用removechild删除其中一个div后,再读取这个overlays时,被删除的这个div还存在吗?
      

  9.   

    你是不是在什么地方又生成了?
    removechild之后就不存在这个div了,除非重新生成。