<html>
<head>
<title>删除节点例子</title>
<script type="text/javascript">
function removeMessage(){
var oHaha=document.body.getElementsByTagName("haha")[0];
oHaha.parentNode.removeChild(oHaha);
}
</script>
</head>
<body onload="removeMessage()">
<haha>"我得意的笑!"</haha>
</body>
</html>?
上面代码有什么问题?为什么删除不了“我得意的笑!”?(ie6和火狐)

解决方案 »

  1.   


    因为你的<haha>是自定义的
    楼主可以用<p>"我得意的笑!"</p>
      

  2.   

    为何ie下用<haha/>不可以?
      

  3.   


    <head> 
    <title>删除节点例子 </title> 
    <script type="text/javascript"> 
    function removeMessage(){ 
    var oHaha=document.body.getElementsByTagName("haha")[0];
    if(document.all) oHaha.parentNode.removeNode(oHaha);
    else oHaha.parentNode.removeChild(oHaha); 

    </script> 
    </head> 
    <body onload="removeMessage()"> 
    <haha>"我得意的笑!" </haha> 
    </body> 
    </html>
      

  4.   

    首先,IE现在并不支持直接在HTML页面上自定义标签,规范的我们用XML.
    当然,如果要实现你的自定义标签也可以:
    第一步:声明你的自定义标签,在<html>中加入 xmlns:haha
    第二步:使用标签<haha:a>
    第三步:通过getElementById()得到你的标签.不能用getElementsByTagName();
    <!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" xmlns:haha>
    <head>
             <script type="text/javascript">

             function removeMessage(){ 
    oHaha = document.getElementById("oo");
    oHaha.parentNode.removeChild(oHaha); 
    }
            </script>
    </head>
            <body>
           <input type="button" value="dddd" onclick="removeMessage()"/>
           <haha:a id="oo">OKOKOOJK</haha:a><br/>
            </body>
    </html>