且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

document.write与document.getElementById.innterHTML的区别

更新时间:2022-09-13 12:50:49

 

document.write与document.getElementById.innterHTML的区别
<html>
<head>
    <meta charset="utf-8">
    <script>
        var tmp = "<iframe src='http://www.cnblogs.com/kaituorensheng/'></iframe>";
        document.write(tmp);
        function getValue()
        {
            document.getElementById("show").innerHTML = tmp;
        }
    </script>
</head>

<body>
<div id = "show" onclick="getValue()">click here</div>
</body>
</html>
document.write与document.getElementById.innterHTML的区别

document.write在页面导入时加载,document.getElementById.innterHTML需要事件触发。

效果

初始

document.write与document.getElementById.innterHTML的区别

点击“click here”后

document.write与document.getElementById.innterHTML的区别

 





本文转自jihite博客园博客,原文链接:http://www.cnblogs.com/kaituorensheng/p/4590349.html,如需转载请自行联系原作者