jquery动态添加与删除div标签

发布时间:2019-08-31编辑:脚本学堂
jquery动态添加与删除div标签的方法,jquery代码动态添加标签,动态删除指定标签元素,需要的朋友参考下。

1、html部分 div标签内容
 

复制代码 代码示例:
<div style="width: 90%; background-image: url(/Content/images/tab.jpg); position: fixed;
border: 1px solid #252525; bottom: 0px; left: 5%;" align="center" id="floatdiv">
<span></span><span style="float: right; background-image: url(/Content/images/split.jpg);
background-repeat: no-repeat;"><span style="padding-left: 10px; padding-right: 10px; cursor:pointer;" onmouseover="showSetting(this.id)" id="close" onmouseout="hiddenSetting(this.id)" >
关闭</span></span><span style="float: right; background-image: url(/Content/images/split.jpg);
background-repeat: no-repeat;"><span style="padding-left: 10px; padding-right: 10px; cursor:pointer;"><img
src="/Content/images/set.jpg" title="设置" alt="设置" onmouseover="showSetting(this.id)" id="setting" onmouseout="hiddenSetting(this.id)" /></span></span>
</div>

2、动态添加删除div标签的js代码
 

复制代码 代码示例:
function showSetting(id) {
var obj = $("#" + id);
var offset = obj.offset();
if (id == "setting") {
$(document.body).append("<img src='/Content/images/set2.jpg' id="set2" style="position:fixed;left:" + offset.left + "px;bottom:28px;"/>");
}
if (id == "close") {
$(document.body).append("<img src='/Content/images/close.jpg' id="set2" style="position:fixed;left:" + offset.left + "px;bottom:28px;"/>");
}
}
function hiddenSetting(id) {
var obj = $("#set2");
obj.remove();
}

您可能感兴趣的文章: