Tree菜单 复选框选中控制DEMO
java 对应实体类属定义
public class AccoSysmanResource{
/**
* 资源类型
*/
private Integer resourceType;
/**
* 权限名称
*/
private String name;
/**
* 权限描述
*/
private String description;
/**
* 排序
*/
private Integer level;
/**
* 子节点
*/
private List<AccoSysmanResource> subResource;
private Integer pid;
private Integer deleteFlag;
private Integer pMenuId;
private Date createtime;
}
jsp页面循环遍历属性结构代码
<!-- tree_start -->
<div class="col-md-3">
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="sour">
<div class="data-div">
<div class="row tableHeader">
<div class="col-lg-11 col-md-11 col-sm-11 col-xs-11">
<label>
<input name="checkname" type="checkbox" value="0" onclick="checkboxById(this,'biz')"/>菜单 全选
</label>
</div>
</div>
<div class="tablebody">
<div id="collapseSystem" class="collapse in" aria-expanded="true">
<!-- 第一层 start -->
<c:forEach items="${bizList}" var="menu" varStatus="rows">
<div class="row">
<div class="col-lg-11 col-md-11 col-sm-11 col-xs-11 levl3" role="button" >
<c:if test="${empty menu.subResource}" var="biz_not_empty_subResource">
<span class="glyphicon glyphicon-pushpin"></span>
</c:if>
<c:if test="${not biz_not_empty_subResource}">
<i id="down_biz_${rows.index}" class="glyphicon glyphicon-hand-down" style="display: ${rows.index==0 ? 'none':''};"></i>
<i id="up_biz_${rows.index}" class="glyphicon glyphicon-hand-up" style="display: ${rows.index!=0 ? 'none':''};"></i>
</c:if>
<label>
<input name="bizMenuId" type="checkbox" value="${menu.pid}" id="biz_${rows.index}" onclick="checkboxById(this,'biz_${rows.index}_')"/>
</label>
<span role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse_biz_${rows.index}" aria-expanded="true" onclick="dom('biz_${rows.index}')">${menu.name}</span>
</div>
</div>
<!-- 第二层 start -->
<c:if test="${not biz_not_empty_subResource}">
<div id="collapse_biz_${rows.index}" class="${rows.index==0 ? 'collapse in':'collapse'}" aria-expanded="${rows.index==0 ? 'true':'false'}">
<c:forEach items="${menu.subResource}" var="m" varStatus="i">
<div class="row" style="border-top:1px solid #E3E8EE;">
<div class="col-lg-11 col-md-11 col-sm-11 col-xs-11 levl3">
<label>
<input name="bizMenuId" value="${m.pid}" type="checkbox" id="biz_${rows.index}_${i.index}" onclick="checkboxById(this,'biz_${rows.index}_${i.index}_')" />
<span role="button" data-toggle="collapse" data-parent="#accordion" aria-expanded="true" href="#collapse_biz_${rows.index}_${i.index}" >
<c:if test="${empty m.subResource}" var="biz_not_empty_m_subResource">
|--${m.name}
</c:if>
<c:if test="${not biz_not_empty_m_subResource}">
<span class="glyphicon glyphicon-triangle-bottom"></span>${m.name}
</c:if>
</span>
</label>
</div>
</div>
<!-- 第三层start -->
<c:if test="${not biz_not_empty_m_subResource}">
<div id="collapse_biz_${rows.index}_${i.index}" class="collapse in" aria-expanded="true" >
<c:forEach items="${m.subResource}" var="m2" varStatus="i3">
<div class="row" style="border-top:1px solid #E3E8EE;">
<div class="col-lg-11 col-md-11 col-sm-11 col-xs-11 levl3" >
<label>
<input name="bizMenuId" value="${m2.pid}" type="checkbox" id="biz_${rows.index}_${i.index}_${i3.index}" onclick="childCheckboxById(this,'biz_${rows.index}_${i.index}_${i3.index}')" />
<span>|----${m2.name}</span>
</label>
</div>
</div>
</c:forEach>
</div>
</c:if>
<!-- 第三层end -->
</c:forEach>
</div>
</c:if>
<!-- 第二层 end -->
</c:forEach>
<!-- 第一层 end -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- tree_end -->
js文件(必须先导入Jquery.js 文件)
/** 全选 */
function checkboxAll(obj, cheName) {
if ($(obj).prop("checked")){
$("input[name='" + cheName + "']").prop("checked", true);
} else {
$("input[name='" + cheName + "']").prop("checked", false);
}
}
/**cheId开头的Id全选*/
function checkboxById(obj, cheId){
var parent2=cheId.substr(0,cheId.lastIndexOf('_'));
var parent1=parent2.substr(0,parent2.lastIndexOf('_'));
if ($(obj).prop("checked")){
$("input[id='" + parent1 + "']").prop("checked", true);
$("input[id^='" + cheId + "']").prop("checked", true);
} else {
$("input[id^='" + cheId + "']").prop("checked", false);
var parent3=parent1+"_";
var index=0;
$("input[id^='"+parent3+"']:checked").each(function(){
index++;
});
if(index==0){
$("input[id='" + parent1 + "']").prop("checked", false);
}
}
}
/**三级节点点击触发**/
function childCheckboxById(obj, parentCheId){
var parent2=parentCheId.substr(0,parentCheId.lastIndexOf('_'));
var parent1=parent2.substr(0,parent2.lastIndexOf('_'));
if ($(obj).prop("checked")){
$("input[id='" + parentCheId + "']").prop("checked", true);
$("input[id='" + parent2 + "']").prop("checked", true);
$("input[id='" + parent1 + "']").prop("checked", true);
} else {
$("input[id='" + parentCheId + "']").prop("checked", false);
var parent3=parent2+"_";
var index=0;
$("input[id^='"+parent3+"']:checked").each(function(){
index++;
});
if(index==0){
$("input[id='" + parent2 + "']").prop("checked", false);
}
var parent4=parent1+"_";
var index2=0;
$("input[id^='"+parent4+"']:checked").each(function(){
index2++;
});
if(index2==0){
$("input[id='" + parent1 + "']").prop("checked", false);
}
}
}
Tree菜单 复选框选中控制DEMO的更多相关文章
- 关于textjs的tree带复选框的树
通过查阅一些资料和自己之前了解到的一些相关知识,有时项目中需要用到.话不多说,先看一下效果图: 我写的这人员选择的树,主要是改写了TreePanel,如下代码: ExtendTreePanel.js ...
- jquery复选框 选中事件 及其判断是否被选中
jquery复选框 选中事件 及其判断是否被选中 (2014-07-25 14:03:54) 转载▼ 标签: jquery复选框选中事件 分类: extjs jquery 今天做了 显示和不显示密 ...
- Web前端之复选框选中属性
熟悉web前端开发的人都知道,判断复选框是否选中是经常做的事情,判断的方法很多,但是开发过程中常常忽略了这些方法的兼容性,而是实现效果就好 了.博主之前用户不少方法,经常Google到一些这个不好那个 ...
- Javascript 统计复选框选中个数
var checked = document.getElementsByName("checked_c[]"); var checked_counts = 0; for(var i ...
- JS复选框选中
Web前端之复选框选中属性 熟悉web前端开发的人都知道,判断复选框是否选中是经常做的事情,判断的方法很多,但是开发过程中常常忽略了这些方法的兼容性,而是实现效果就好了.博主之前用户不少方法,经常 ...
- springMvc接收ajax数组参数,以及jquery复选框选中、反选、全选、全不选
一.复选框选中.反选.全选.全不选 html代码: <input type='checkbox' name='menuCheckBox' value='10' >苹果 <input ...
- Jquery获取当前页面中的复选框选中的内容
在使用$.post提交数据时,有一个数据是复选框获取数据,所以在当前页面获取到复选框选中的值并提交到后端卡住了一下,解决方法如下: 这两个input就是复选框的内容: str += "< ...
- CheckStateChanged(复选框选中状态更改事件)和 CheckedChanged(单选按钮选中状态更改事件)二者区别?
CheckStateChanged(复选框选中状态更改事件)和 CheckedChanged(单选按钮选中状态更改事件)二者区别: 复选框控件(CheckBox)提供了CheckedChanged控件 ...
- bootstrap table 复选框选中后,翻页不影响已选中的复选框
使用的 jquery版本为 2.1.1 在项目中发现bootstrap table的复选框选中后,翻页操作会导致上一页选中的丢失,api中的 bootstrapTable('getSelections ...
随机推荐
- 正确解读free -m
如下显示free是显示的当前内存的使用,-m的意思是M字节来显示内容.我们来一起看看. $ free -m total used free shared buffers cachedMem: 1002 ...
- display:none与visible:hidden的区别 slideDown与
display:none与visible:hidden的区别 display:none和visible:hidden都能把网页上某个元素隐藏起来,但两者有区别: display:none ---不为被 ...
- Oracle10g 表分区
1.分区的原因 (1)Tables greater than 2GB should always be considered for partitioning. (2)Tables containin ...
- [转载] Java CheckBoxTree
代码基本上是copy的.只是在使用上有一些自己的想法. 先上code吧! 虽然别的地方也有.但是还是转一份给自己. 出处:http://blog.csdn.net/joy_125/article/de ...
- cron(CronTrigger)表达式用法
CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...
- MySQL--InnoDB索引原理详解
1 各种树形结构 本来不打算从二叉搜索树开始,因为网上已经有太多相关文章,但是考虑到清晰的图示对理解问题有很大帮助,也为了保证文章完整性,最后还是加上了这部分. 先看看几种树形结构: 1 搜索二叉树: ...
- cnetos7.0 安装mysql
CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载 [root@localhost ~]# wget http://dev.mysql.com/ge ...
- Android中surface,surfaceview,sufaceholder以及surface客户端的关系
这里以照相机camera功能的实现来解释surface,surfaceview,sufaceholder以及surface客户端(本例子中指的是camera)的关系,surface及其client(客 ...
- js获取浏览器body或窗宽度高度合集
<script type="text/javascript"> var s = " "; document.documentElement.scro ...
- ubuntu 14.04下spark简易安装
java安装 首先需要上oracle的网站下载 在lib目录下建立一个jvm文件夹 sudo mkdir /usr/lib/jvm 然后解压文件到这个文件夹 sudo tar zxvf jdk-8u4 ...