基于bootstrap面板的类别多选栏
2024-10-18 21:23:51
1、html部分
<div class="panel panel-default">
<div class="panel-heading">请选择您需要的分类(可多选)</div>
<div class="list-group" id="category">
<a href="#" class="list-group-item"><span class="glyphicon glyphicon-ok" ></span><p>前端</p></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon-ok" ></span><p>后台</p></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon-ok" ></span><p>iOS</p></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon-ok" ></span><p>java</p></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon-ok" ></span><p>测试</p></a>
<a href="#" class="list-group-item" id="newCategory"><span class="glyphicon glyphicon-ok " ></span>
<p>自定义</p>
<div >
<input style="position:relative;width:70%;float:left;" type="text" maxlength="10" placeholder="请输入要添加的类别" class="form-control" name="" >
<button style="float:right;" class="btn btn-primary">添加</button>
</div>
</a>
</div>
<button style="width:30%; float:right;margin-top: 15px;" id="returnNewTask" class="btn btn-success">确定</button>
</div>
2、js
//类别多选栏的样式(小绿勾)
var $category = $("#category");
$category.delegate("a", "click", function (e) {
if ($(this).index() == $("#category a").length - 1) {
$('#newCategory div').css("display", "block");
}
else {
$('#newCategory div').css("display", "none");
$("#newCategory input").val("");
if ($(this).is(".active")) {
$(this).removeClass("active");
}
else {
$(this).addClass("active");
}
;
}
}); $("#newCategory button").on("click", function () {
var item = '<a href="#" class="list-group-item active"><span class="glyphicon glyphicon-ok" ></span><p>' +
$("#newCategory input").val() + '</p></a>';
$("#newCategory").before(item);
$("#newCategory input").val("");
})
3、css
/*******类别多选栏的部分******/
#category .active{
background-color: white;
color: black;
border: 1px solid #E2E2E3;
} #category .badge{
margin-top: -4px;
background-color:transparent;
border: none;
} #category span{
float:right;
display:none;
} #category .active span{
display:block;
float:right;
color: rgb(70, 176, 85);
font-size: 15px;
} #options a{
overflow: hidden;
} #options .panel{
width:100%;
margin-left: auto;
margin-right: auto;
} #newCategory div{
display: none;
}
最新文章
- C#冒泡排序算法
- OFFSET IN 使用举例
- Linux下的删除命令
- 解析Path方法备忘
- Public, Private and Protect
- CentOS 6.5 下载地址
- 再eclipse的javaweb项目中添加JQuery文件时jquery-2.1.4.min.js报错
- IE9的BUG?jQuery的BUG?
- MySQL server version for the right syntax to use near &;#39;type=InnoDB&;#39; at line 1
- poj1094 topsort
- 数据可视化-使用EXCEL和PS制作一个复杂饼图
- 跟着刚哥梳理java知识点——泛型(十三)
- poj3020二分图匹配
- 15套java互联网架构师、高并发、集群、负载均衡、高可用、数据库设计、缓存、性能优化、大型分布式 项目实战视频教程
- [LeetCode] Redundant Connection 冗余的连接
- HttpPost方式调用接口的3种方式
- pandas pivot_table或者groupby实现sql 中的count distinct 功能
- IE、360浏览器select属性onchange遇到的坑
- Makefile ------ := ?= += =的区别
- docker基础:dockerfile的介绍