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>
运行效果: