JS中innerHTML,innerText,value

JS中getElementById后我们取什么? - Holyson - 凡图的编程之路

 

innerHTML

<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p id="demo">My First Paragraph.</p>
<script>
document.getElementById("demo").innerHTML="<h1>My First JavaScript</h1>";
</script>
</body>
</html>

输出结果:

My First Web Page

My First Javascript

innerText

<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p id="demo">My First Paragraph.</p>
<script>
document.getElementById("demo").innerText="<h1>My First JavaScript</h1>";
</script>
</body>
</html>

输出结果:

My First Web Page

<h1>My First Javascript</h1>

value

<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p id="demo">My First Paragraph.</p>
<script>
document.getElementById("demo").value="<h1>My First JavaScript</h1>";
</script>
</body>
</html>

输出结果:

My First Web Page

My First Paragraph.

转载自:http://holysonll.blog.163.com/blog/static/21413909320134111054352/

posted @ 2014-07-09 11:42  Json_wangqiang  阅读(474)  评论(0编辑  收藏  举报