本帖最后由 laiwenyu1012 于 2009-09-24 22:00:03 编辑

解决方案 »

  1.   


    <SCRIPT LANGUAGE="JavaScript"> 
    function doit(){
       document.getElementsByTagName("p")[0].innerHTML = "";
    }
    window.onload=function(){
    document.getElementById("btn").focus();
    }
    </SCRIPT> 
    <html> 
    <head> </head> 
    <body> 
    <p> 
    <input> </input> 
    <a> xxxx</a> 
    </p>
    <input type="button" id="btn" value="按ENTER" onclick="doit();">
    </body> 
    </html>
      

  2.   

    document.getElementsByTagName("p")[0].innerHTML = "";
    hookee,谢谢你的回答,不过我不能用此方法来删掉<p>标签后的内容,因为有些东西不能放进<p>中,所以不知可否有函数能直接删掉p后的内容。
      

  3.   


    <SCRIPT LANGUAGE="JavaScript"> 
    function doit(){
          var obj = document.getElementsByTagName("p")[0];
          var a = []
          obj = obj.nextSibling;
          while(obj!=null){
           a.push(obj)
             obj = obj.nextSibling;
          }
          for(var i=0;i<a.length;i++) a[i].removeNode(true);
    }
    window.onload=function(){
        document.getElementById("btn").focus();
    }
    </SCRIPT> 
    <html> 
    <head> </head> 
    <body> 
    <input type="button" id="btn" value="按ENTER" onclick="doit();">
    <p>P中</p>
    <input></input> 
    <a>xxxx</a>
    </body> 
    </html>