<!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" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
最后增
function fn1(){
var zeng=document.createElement('li');
var wen=document.createTextNode('5');
zeng.appendChild(wen);
var gul=document.getElementsByTagName('ul')[0];
gul.appendChild(zeng);
}
//在什么前增
function fn2(){
var zeng=document.createElement('li');
var wen=document.createTextNode('5');
zeng.appendChild(wen);
var gul=document.getElementsByTagName('ul')[0];
var ping=gul.children[3];
gul.insertBefore(zeng,ping);
}
//删除
function fn3(){
var gul=document.getElementsByTagName('ul')[0];
var dy=gul.children[2];
gul.removeChild(dy);
}
//修改
function fn4(){
var zeng=document.createElement('li');
var wen=document.createTextNode('22');
zeng.appendChild(wen);
var fu=document.getElementsByTagName('ul')[0];
var zi=fu.children[1];
fu.replaceChild(zeng,zi);
}
</script>
<style type="text/css">
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<input type="button" value="增加节点5" οnclick="fn1();"/>
<input type="button" value="增加节点在4前面" οnclick="fn2();"/>
<input type="button" value="删除3" οnclick="fn3();"/>
<input type="button" value="把2改为22" οnclick="fn4();"/>
</body>
</html>
节点 增删改
最新推荐文章于 2023-03-01 00:02:55 发布