<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">html
<html xmlns="http://www.w3.org/1999/xhtml">app
<head>ui
<title>刪除節點,建立節點</title>spa
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />xml
<meta name="description" content="布爾教育 http://www.itbool.com" />htm
</head>對象
<body>ip
<input type="button" value="刪除一個節點" onclick="del();"/>utf-8
<ul>rem
<li>春</li>
<li>夏</li>
<li>秋</li>
<li>冬</li>
</ul>
</body>
<script>
function del(){
//刪除標籤
var lis=document.getElementsByTagName('li');
var last=lis[lis.length-1];
//刪除子對象
last.parentNode.removeChild(last);
}
</script>
</html>
/*****************************************/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>建立節點</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="布爾教育 http://www.itbool.com" />
</head>
<body>
<h1>建立節點</h1>
<input type="button" value="增長" onclick="add()"/>
<ul>
<li>春</li>
<li>夏</li>
<li>秋</li>
</ul>
</body>
<script>
function add(){
//建立節點
var li=document.createElement('li');
var text=document.createTextNode('冬');
li.appendChild(text);
document.getElementsByTagName('ul')[0].appendChild(li);
}
</script>
</html>
/***********************************/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>暴力添加節點</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="布爾教育 http://www.itbool.com" />
</head>
<body>
<input type="button"value="添加春夏秋" onclick="add3()" />
<input type="button" value="添加冬" onclick="add1()"/>
<ul></ul>
</body>
<script>
function add3(){
var ul=document.getElementsByTagName('ul')[0];
ul.innerHTML='<li>春</li><li>秋</li><li>夏</li>';
}
function add1 () {
var ul=document.getElementsByTagName('ul')[0];
ul.innerHTML+='<li>冬</li>'
}
</script>
</html>