想点击一次删除一个子节点,为什么必须点击两次才能删除一个???
想点击一次删除一个子节点,为什么必须点击两次才能删除一个???
2015-01-07
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <!DOCTYPE HTML> <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>无标题文档</title> </head> <body> <div id= "content" > <h1>html</h1> <h1>php</h1> <h1>javascript</h1> <h1>jquery</h1> <h1>java</h1> </div> <script type= "text/javascript" > function firstChilds(data){ var dd = data.firstChild while (dd.nodeType != 1){ data.removeChild(dd); dd = data.firstChild } return dd } function clearText() { var content=document.getElementById( "content" ); // 在此完成该函数 var x = content.removeChild(firstChilds(content)); x = null ; } </script> <button onclick= "clearText()" >清除节点内容</button> </body> </html> |
在谷歌浏览器测试过,没问题
举报