补充一下主要是function del()这个函数怎么判断元素是否已经存在了。多谢各位能够给予解答!

解决方案 »

  1.   

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="JavaScript">
    function add(){
    newObj = document.createElement('Input');
    newObj.id="tttttt";
    newObj.type="text";
    newObj.name="mytest";
    newObj.value="hello";
    currectObj = document.getElementById('p1');

     currectObj.appendChild(newObj);
    }
    function del(){
      if(document.getElementById('tttttt')  != null){
        alert("It Exist!");
      }
    }
    </script>
    </head><body><form name="form1" method="post" action="">
      <p id="p1">&nbsp;</p>
      <input type="button" name="Button" value="add" onClick="add();">
      <input type="button" name="Button" value="del" onClick="del();">
    </form>
    <p>&nbsp;</p>
    </body>
    </html>