使用jquery的方法和技巧2,点击多选框的jquery响应
使用jquery来控制多选框的变化

功能描述:
1、第一层
当选中后台应用(App1)时,所有多选框都被选择。
当取消选中后台应用(App1)时,所有多选框都被取消选择。
第一层的逻辑如下:

2、第二层
a.对所有亲子多选框而言
当选择帖子管理(控制器Action02)时,所有亲子多选框被选择。
当取消选择帖子管理(控制器Action02)时,所有亲子多选框被取消选择。
b.对亲父级多选框:后台应用(App1)而言
当选择帖子管理(控制器Action02)时,亲父App多选框被选择。
当取消选择帖子管理(控制器Action02)时,
1)如果亲兄Action有被选中的,亲父App多选框被选择。
2)如果亲兄Action没有被选中的,亲父App多选框被取消选择。
第二层的逻辑如下:

第三层:
分析略。
逻辑见图

==========================思路如上==========================
==========================代码如下==========================
1、ThinkPHP中部署的html
<foreach name="node" item="app">
<div class="app">
<p>
<label style="cursor:pointer" for="app_{$app.id}_1">
<strong>{$app.title}</strong>
<input type="checkbox" name="access[]" id="app_{$app.id}_1" value="{$app.id}_1" level="1" />
</label>
</p> <span class="action">
<foreach name="app.child" item="action">
<dl>
<dt>
<label style="cursor:pointer" for="action_{$action.id}_2">
<strong>{$action.title}</strong>
<input type="checkbox" name="access[]" id="action_{$action.id}_2" value="{$action.id}_2" level="2" />
</label>
</dt> <span class="method">
<foreach name="action.child" item="method">
<dd>
<label style="cursor:pointer" for="method_{$method.id}_3">
<span>{$method.title}</span>
<input type="checkbox" name="access[]" id="method_{$method.id}_3" value="{$method.id}_3" level="3" />
</label>
</dd>
</foreach>
</span> </dl>
</foreach>
</span> </div>
</foreach>
html代码
2、html的头部标签中部署的jquery代码
<script type="text/javascript" src="__PUBLIC__/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
//这里面使用jquery的方法
$(function(){
$('input[level=1]').click(function(){
var inputs_all=$(this).parents('div.app').find('input');
if ($(this).attr('checked')=="checked") {
inputs_all.attr('checked','checked');
}else{
inputs_all.removeAttr('checked');
}
});
$('input[level=2]').click(function(){
var all_born_children=$(this).parents('dt').next('span.method').find('input');
var born_parent=$(this).parents('span.action').prev().find('input');
var born_brothers=$(this).parents('dl').siblings().children('dt').find('input');
// var tbody = "";//调试代码
var cunzai2=0;
$.each(born_brothers,function(n,value){
if(value.checked==true){
cunzai2++;
}
//alert(n+' '+value);//调试代码
// var trs = "";//调试代码
// trs += "<tr><td>" + value.checked +cunzai2+ "</td></tr>";//调试代码
// tbody += trs;//调试代码
});
// $("#project").append(tbody);//调试代码
if ($(this).attr('checked')=="checked") {
all_born_children.attr('checked','checked');
born_parent.attr('checked','checked');
}else{
all_born_children.removeAttr('checked');
if (cunzai2==0) {
born_parent.removeAttr('checked');
}else{
born_parent.attr('checked','checked');
}
}
});
$('input[level=3]').click(function(){
var born_father=$(this).parents('span.method').prev().find('input');
var born_grandpa=$(this).parents('span.action').prev().find('input');
var born_brother=$(this).parents('dd').siblings().find('input');
var born_uncle=$(this).parents('dl').siblings().children('dt').find('input');
//判断兄弟节点是否被选中
var cunzai3_1=0;
$.each(born_brother,function(n,value){
if(value.checked==true){
cunzai3_1++;
}
});
//判断叔伯节点是否被选中
var cunzai3_2=0;
$.each(born_uncle,function(n,value){
if(value.checked==true){
cunzai3_2++;
}
});
if ($(this).attr('checked')=="checked") {
born_father.attr('checked','checked');
born_grandpa.attr('checked','checked');
}else{
if (cunzai3_1!=0) {
born_father.attr('checked','checked');
born_grandpa.attr('checked','checked');
}else{
born_father.removeAttr('checked');
if (cunzai3_2==0) {
born_grandpa.removeAttr('checked');
}else{
born_grandpa.attr('checked','checked');
}
}
}
});
});
</script>
jquery为主的代码
完。
使用jquery的方法和技巧2,点击多选框的jquery响应的更多相关文章
- jquery点击复选框触发事件给input赋值
体验效果:http://keleyi.com/keleyi/phtml/jqtexiao/31.htm 代码如下: <!DOCTYPE html> <html xmlns=" ...
- 使用jquery的方法和技巧
1.下载一个jquery.js的文件 2.引入jquery.js文件 <script type="text/javascript" src="__PUBLIC__/ ...
- 【六】jquery之HTML代码/文本/值[下拉列表框、多选框、单选框的选中]
val()方法不仅能设置元素的值,同时也能获取元素的值.另外,val()方法还有另外一个用处,就是它能使select(下拉列表框).checkbox(多选框)和radio(单选框)相应的选项被选中,在 ...
- 模拟多级复选框效果--jquery
今天又次体会到jquery的强大了,做了个多级复选框的效果,代码总共就20+行就over了. 我又想用js来做一个看看,才写了几个方法就写不动了,兼容性要考虑很多,而且代码量直线上升. 主要分享下jq ...
- jquery中attr和prop的区别—判断复选框选中状态
最近项目中需要用jquery判断input里checkbox是否被选中,发现用attr()获取不到复选框改变后的状态,最后查资料发现jQuery 1.6以后新增加了prop()方法,借用官方的一段描述 ...
- jquery 循环获取checkBox的值,以及对复选框选中,取消,操作按钮
法一:jquery 循环获取选中checkBox框的值 function checkeds() { $("input:checkbox").each(function(index) ...
- jQuery v1.10.2如何判断checkbox(复选框)是否被选中
做项目时,我们经常会用到jquery来做一些判断,今天自己遇上判断复选框是否选中,然后搜索查看,发现现在网上的都是错误的,下面罗列错误的: 1.$("#id").attr(&quo ...
- jquery easyui datagraid 对象显示的方法与datagraid、分页、复选框多选的数据显示
========================jsp==============================<table id="dg" fit="true& ...
- 【jQuery学习】用JavaScript写一个输出多选框的个数报错:Cannot set property 'onclick' of null"
说明:代码段来源于:<锋利的jQuery> 根据代码段我补充的代码如下: <!DOCTYPE html> <html> <head> <meta ...
随机推荐
- jquery表单验证源码
/**数据验证完整性**/$.fn.Validform = function () { var Validatemsg = ""; var Validateflag = ...
- sgu102 Coprimes
102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB For given integer N (1&l ...
- [2017-07-18]logstash配置示例
提醒 /etc/logstash/conf.d/下虽然可以有多个conf文件,但是Logstash执行时,实际上只有一个pipeline,它会将/etc/logstash/conf.d/下的所有con ...
- window的设置属性
1.windowAnimationStyle 用于设置一组window动画的引用style资源,window的动画属性由R.styleable.WindowAnimation定义. Winow动画类属 ...
- jQuery对象和DOM对象和字符串之间的转化
jQuery对象和DOM对象和字符串之间的转化 字符串---------->jQuery对象 $(HTML字符串): $('<div>我是祖国的一朵小花</div>') ...
- jquery_mobile事件
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 < ...
- spring配置和注解事务同时存在导致的事务嵌套
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt123 首先先看配置文件: [html] view plaincopy < ...
- java 实现微博,QQ联合登录
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt313 开发平台 http://connect.qq.com/ http:/ ...
- 花生壳DDNS为何不支持LetsEncrypt申请
Inspired by Let's Encrypt Community , thx to sahsanu, jsha, and orzorc. 开端 Lets Encrypt 是一款免费的网站 SSL ...
- [ASP.NET MVC]笔记(四 UnobtruSive AJAX和客户端验证
UnobtruSive AJAX和客户端验证 ASP.NET MVC 已经默认开启非侵入试js和客户端验证,在web.config可以看到如下配置: <configuration> < ...