JS点击动态添加标签、删除指定标签的代码1.div标签
<div id="mDiv3">
<p>1</p> <button onclick="myFun9()">添加</button>
</div>
2.js
function myFun9() {
var mDiv3 = ElementById("mDiv3"); //获取组件1
var eleme = ateElement("p"); //创建组件2
var ele_content = ateTextNode("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 ElementById("mDiv4");
js实现轮播图最简代码var ElementById("p1");
}
补充:
下⾯看下js-动态⽣成⼩圆点(根据轮播图图⽚张数动态⽣成⼩圆点)
动态⽣成⼩圆点(根据轮播图图⽚张数动态⽣成⼩圆点)
<!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>
function $(id){ ElementById(id); } //动态⽣成轮播图⼩圆点
var circle = ateElement("div");
circle.setAttribute("class","circle");
var lis = ElementsByTagName("li");
for(var i=0; i<lis.length; i++){
var span = ateElement("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>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论