这次给大家带来怎样操作JS动态添加标签与删除标签,怎样操作JS动态添加标签与删除标签的注意事项有哪些,下面就是实战案例,一起来看一下。
1.p标签
<p> </p><p>1</p> <button>添加</button>
2.js
function myFun9() {
var mp3 = document.getElementById("mp3"); //获取组件1
var eleme = document.createElement("p"); //创建组件2
var ele_content = document.createTextNode("2");//创建节点内容
eleme.appendChild(ele_content); // 组件添加节点
mp3.appendChild(eleme); //组件2加入组件1
}
==================删除==============================
<button>删除</button>
<p>
</p><p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill10340" title="arcgis-js"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20e352aa140.jpg" alt="arcgis-js" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill10340" title="arcgis-js" class="overflowclass">arcgis-js</a>
<p class="overflowclass">提供 ArcGIS Maps SDK for JavaScript 开发辅助,涵盖 2D/3D 地图视图、图层管理、数据可视化、空间分析等功能模块的参考和示例指导。</p>
</div>
<a rel="nofollow" href="/xiazai/skill10340" title="arcgis-js" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
function myFun10(){
var parent=document.getElementById("mp4");
var son=document.getElementById("p1");
parent.removeChild(son);
}
补充:
下面看下js-动态生成小圆点(根据轮播图图片张数动态生成小圆点)
动态生成小圆点(根据轮播图图片张数动态生成小圆点)
html>
<meta>
<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("p");
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>
<p>
</p>
- @@##@@
- @@##@@
- @@##@@
- @@##@@
- @@##@@
- @@##@@
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:










