innerHTML .innerText区别

().innerHtml("“):改变html元素;

().innerTEXT(”“):改变文本元素;

 试验代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>显示日期</title>
    <script>
        function displayDate(){
            document.getElementById("demo").innerHTML=Date();
        }

    </script>
</head>
<body>
<h1>this is javascript</h1>
<p id="demo0">this is a section</p>
<p id ="demo1">this is a section</p>
<SCRIPT>
    document.getElementById("demo0").innerHTML="<h1>innerHTML,改变html元素</h1>"
    document.getElementById("demo1").innerText="<h1>innerText,只改变文本</h1>"
</SCRIPT>
</body>
</html>

运行效果:

 

posted @ 2018-11-05 13:29  第101次弃游  Views(140)  Comments(0Edit  收藏  举报