document.write的注意点

如果给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>

原文地址:https://www.cnblogs.com/tangdiying/p/10098632.html