如果给button点击事件添加document.write会消除页面所有元素,包括button按钮
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <button value="点击"></button> <script type="text/javascript"> var obtn = document.getElementsByTagName("button")[0]; document.write(123); obtn.onclick = function(){ document.write(456); } </script> </body> </html>