分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

JQuery添加删除标签

发布时间:2023-09-06 01:06责任编辑:蔡小小关键词:暂无标签

html

________________________________________________________________________

<!DOCTYPE html>
<html>
<head>
???<meta charset="UTF-8">
???<script src="../js/jquery-3.2.1.min.js"></script>
???<link rel="stylesheet" href="../css/JQ08_24_04.css">
???<title>添加标签</title>
</head>
<body>
<div>
???<a href="javascript: return false">标签<span>X</span></a>
</div>
<input type="button" value="添加标签">
<script src="../js/JQ08_24_04.js"></script>
</body>
</html>


css
______________________________________________________
*{margin: 0;padding: 0}
a{text-decoration: none}
div{
???background: #e2e2e2;
???height: 500px;
}
a{
???position: relative;
???display: block;
???width: 80px;
???height: 30px;
???line-height: 30px;
???color: white;
???background: green;
???text-align: center;
???margin: 0 5px;
???float: left;
}
span{
???position: absolute;
???color: red;
???right: 5px;
}

js
_________________________________________________________
$(function () {
???$("input").click(function () {
???????$("div").append("<a href=‘javascript: return false‘>标签<span>X</span></a>");
???});
???//事件委托至document,利用on()给所有未渲染的标签绑定click事件,冒泡传递给document
???$(document).on("click","span",function () {
???????var i = $(this).index();
???????$("a").eq(i).remove();
???})
});

JQuery添加删除标签

原文地址:http://www.cnblogs.com/AgilityJin/p/7425851.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved