鼠标拖拽删除
2018-06-24 01:00:36来源:未知 阅读 ()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
ul,li{
margin: 0;
padding: 0;
list-style: none;
}
#box{
width: 400px;
height: 420px;
background-color: pink;
padding-top: 30px;
margin: auto;
}
.title,.end{
width: 300px;
margin: auto;
}
input{
width: 280px;
height: 80px;
border-radius: 10px;
padding: 0 10px;
margin: 0;
border:0;
}
.text{
display: inline-block;
width: 300px;
height: 30px;
border-radius: 10px;
background-color: red;
text-align: center;
line-height: 30px;
margin-top: 15px;
}
.end{
margin-top: 10px;
}
li{
width: 100%;
height: 30px;
overflow: hidden;
line-height: 30px;
}
.row{
float: left;
}
.delete{
float: right;
cursor: pointer;
}
</style>
</head>
<body>
<div id="box">
<div class="title">
<input type="text">
<span class="text">提交</span>
</div>
<ul class="end"></ul>
</div>
<script>
//获取需要操作的元素
var inp = document.querySelector('input');
var btn = document.querySelector('.text');
var end = document.querySelector('.end');
//添加点击事件
btn.onclick = function () {
//如果没有输入内容时要做的事情
if(inp.value == ''){
alert('请输入内容');
return;
}
//生成输入的内容
end.innerHTML += '<li><span class="row">'+inp.value+'</span><span class="delete">删除</span></li>';
//清空value值
inp.value = '';
}
//点击事件
end.onclick = function(ev){
var ss = ev.target;
//绑定事件 利用父级删除子级;
if(ss.getAttribute('class')=='delete'){
end.removeChild(ss.parentNode);
}
}
</script>
</body>
</html>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:关于移动端的滑动无效的问题
- 如何用算法删除重复数据 2020-03-18
- 微信小程序开发图片拖拽实例详解 2020-03-16
- 鼠标滑过出现预览的大图提示效果 2020-02-21
- 鼠标悬浮停留三秒后自动显示大图js代码 2020-02-21
- 鼠标滚轮控制网页横向移动实现思路 2020-02-20
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
