原文:http://holysonll.blog.163.com/blog/static/21413909320134111054352/
JS中innerHTML,innerText,value
2013-05-11 11:24:49| 分类: JS与JQ | 标签:.innerhtml .value innertext |举报 |字号大中小 订阅
.value是一个介于innerHTML和innerText的效果
既不会显示代码,还可以显示文本
<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <pid="demo">My First Paragraph.</p> <script> document.getElementById("demo").innerHTML="<h1>My First JavaScript</h1>"; </script> </body> </html>
输出结果:
MyFirstWebPage
MyFirstJavascript
innerText
<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <pid="demo">My First Paragraph.</p> <script> document.getElementById("demo").innerText="<h1>My First JavaScript</h1>"; </script> </body> </html>
输出结果:
MyFirstWebPage
<h1>MyFirstJavascript</h1>
value
<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <pid="demo">My First Paragraph.</p> <script> document.getElementById("demo").value="<h1>My First JavaScript</h1>"; </script> </body> </html>
输出结果:
MyFirstWebPage
MyFirstParagraph.