欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript使用appendChild追加節(jié)點實例

 更新時間:2015年01月12日 11:31:24   投稿:shichen2014  
這篇文章主要介紹了javascript使用appendChild追加節(jié)點的方法,實例分析了appendChild()函數(shù)增加結(jié)點的使用技巧,需要的朋友可以參考下

本文實例講述了javascript使用appendChild追加節(jié)點的方法。分享給大家供大家參考。具體分析如下:

DOM樹節(jié)點的增加,實例代碼如下:

復(fù)制代碼 代碼如下:
<html>
<head>
<script type="text/javascript">
function t(){
 var nodep = document.createElement('p');//創(chuàng)建p節(jié)點
 var art = document.createTextNode('你好,世界');//創(chuàng)建文本節(jié)點
 
 var cont = document.getElementById('container');//獲取節(jié)點
 cont.appendChild(nodep);//增加節(jié)點
 nodep.appendChild(art);//增加文本節(jié)點
}
</script>
<style type="text/css">
p{width:100px;height:100px;background:green;}
#container p{width:100px;height:100px;background:blue;}
</style>
</head>
<body>
<div id="container"><p>hello world</p>
</div>
<p>說兩句吧</p>
<hr />
<button onclick="t()" value="">增加節(jié)點</button>
</body>
</html>

希望本文所述對大家的javascript程序設(shè)計有所幫助。

相關(guān)文章

最新評論