function myfun9() {
var mdiv3 = document.getelementbyid("mdiv3"); //获取组件1
var eleme = document.createelement("p"); //创建组件2
var ele_content = document.createtextnode("2");//创建节点内容
eleme.appendchild(ele_content); // 组件添加节点
mdiv3.appendchild(eleme); //组件2加入组件1
}
==================删除==============================
<button onclick="myfun10()">删除</button>
<div id="mdiv4">
<p id="p1">1</p>
<p id="p2">2</p>
<p id="p3">3</p>
<p id="p4">4</p>
<p id="p5">5</p>
</div>
function myfun10(){
var parent=document.getelementbyid("mdiv4");
var son=document.getelementbyid("p1");
parent.removechild(son);
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>document</title>
<style>
body,ul{
padding: 0;
margin: 0;
}
ul{
list-style: none;
}
.lunbo{
width: 730px;
height: 454px;
margin: 100px auto;
overflow: hidden;
position: relative;
}
.circle{
position: absolute;
left: 50%;
margin-left: -50px;
bottom: 10px;
}
.circle span{
display: inline-block;
width: 18px;
height: 18px;
background-color: #ccc;
text-align: center;
border-radius: 18px;
cursor: pointer;
margin-right:10px;
}
.circle span.current{
background-color: yellow;
}
</style>
<script>
window.onload = function(){
function $(id){ return document.getelementbyid(id); }
//动态生成轮播图小圆点
var circle = document.createelement("div");
circle.setattribute("class","circle");
var lis = document.getelementsbytagname("li");
for(var i=0; i<lis.length; i++){
var span = document.createelement("span");
span.innerhtml = i+1;
circle.appendchild(span);
}
$("scroll").appendchild(circle);
var spanchildren = circle.children;
spanchildren[0].setattribute("class","current");
}
</script>
</head>
<body>
<div class="lunbo" id="scroll">
<ul id="ul">
<li><img src="images/11.jpg" alt=""></li>
<li><img src="images/22.jpg" alt=""></li>
<li><img src="images/33.jpg" alt=""></li>
<li><img src="images/44.jpg" alt=""></li>
<li><img src="images/55.jpg" alt=""></li>
<li><img src="images/66.jpg" alt=""></li>
</ul>
<!-- <div class="circle">
<span>1</span>
<span class="current">2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
</div> -->
</div>
</body>
</html>