html中全选和反选怎么写,html中全选反选

chartor4.png

OM系统

chartor5.png

发货方管理

查询货主

查询货主

查询货主

.first {

overflow: hidden;

margin-left:10%;

}

.first_top {

font-size: 16px;

}

.first_top img {

float: left;

margin-right: 10px;

cursor: pointer;

}

.first_top input {

18px;

height: 18px;

border:1px solid #ccc;

background: #fff !important;

float: left;

background-color: #f4a100 !important;

margin-right: 10px;

}

.second_top {

font-size: 16px;

margin-left: 4%;

margin-top: 1%;

}

.second_top img {

float: left;

margin-right: 10px;

cursor: pointer;

}

.second_top input {

18px;

height: 18px;

box-sizing: border-box;

border:1px solid #ccc;

background: #fff !important;

float: left;

background-color: #f4a100;

margin-right: 10px;

}

.thired_top {

font-size: 16px;

margin-left: 12%;

margin-top: 1%;

}

.thired_top img {

float: left;

margin-right: 10px;

}

.thired_top input {

18px;

height: 18px;

box-sizing: border-box;

border:1px solid #ccc;

background: #fff !important;

float: left;

background-color: #f4a100;

margin-right: 10px;

}

第一种:子级盒子全选中父级盒子选中

e2e95c67c25ad35666189a89463d4684.png

4738816a688adf44051640e3ff8d4cda.png

//盒子折叠

//第一层

$(".first-img").click(function(){

$(this).parent().siblings().slideToggle(500);

});

//第二层

$(".second-img").click(function(){

$(this).parent().siblings().slideToggle(500);

});

//全选反选

//第一层全选

$("#all").click(function() {

var op = $(this).parent().siblings().find("input[name='resUuids']");

var pp = $(this).parent().siblings().find("input[name='resUuid']");

op.prop("checked", this.checked);

pp.prop("checked", this.checked);

});

//第二层全选

$(".second-inp").click(function() {

var op = $(this).parent().siblings().find("input[name='resUuids']");

op.prop("checked", this.checked);

});

//第三层反选

$(".third-inp").click(function() {

var lb = $(this).parent().parent().find('.third-inp');

varall = $(this).parent().parent().parent().parent().find('.second-inp');

//给第二层盒子加上选中

for(var i=0;i

//if($(lb[i]).prop("checked") == true){

//$(this).parent().parent().siblings().find('.second-inp').prop("checked", true);

//break

//}else{

//$(this).parent().parent().siblings().find('.second-inp').prop("checked", false);

//}

if($(lb[i]).prop("checked") == false){

$(this).parent().parent().siblings().find('.second-inp').prop("checked", false);

break

}else{

$(this).parent().parent().siblings().find('.second-inp').prop("checked", true);

}

}

//给第一层盒子加上选中

for(var j=0;j

if($(all[j]).prop("checked") == false){

$(this).parent().parent().parent().parent().find('.first-inp').prop("checked", false);

break ;

}else{

$(this).parent().parent().parent().parent().find('.first-inp').prop("checked", true);

}

}

});

//第二层反选

$(".per-index").click(function() {

var nb = $(this).parent().parent().parent().find('.per-index');

for(var i=0;i

if($(nb[i]).prop("checked") == false){

$(".first-inp").prop("checked", false);

return ;

}else {

$(".first-inp").prop("checked", true);

}

}

});

第二种:子级盒子只要有一个被选中父级盒子就被选中

5108f7c2cc28caf18a21430f4b4779bd.png

//盒子折叠

//第一层

$(".first-img").click(function(){

$(this).parent().siblings().slideToggle(500);

});

//第二层

$(".second-img").click(function(){

$(this).parent().siblings().slideToggle(500);

});

//全选反选

//第一层全选

$("#all").click(function() {

var op = $(this).parent().siblings().find("input[name='resUuids']");

var pp = $(this).parent().siblings().find("input[name='resUuid']");

op.prop("checked", this.checked);

pp.prop("checked", this.checked);

});

//第二层全选

$(".second-inp").click(function() {

var op = $(this).parent().siblings().find("input[name='resUuids']");

op.prop("checked", this.checked);

});

//第三层反选

$(".third-inp").click(function() {

var lb = $(this).parent().parent().find('.third-inp');

varall = $(this).parent().parent().parent().parent().find('.second-inp');

//给第二层盒子加上选中

for(var i=0;i

if($(lb[i]).prop("checked") == true){

$(this).parent().parent().siblings().find('.second-inp').prop("checked", true);

break

}else{

$(this).parent().parent().siblings().find('.second-inp').prop("checked", false);

}

//if($(lb[i]).prop("checked") == false){

//$(this).parent().parent().siblings().find('.second-inp').prop("checked", false);

//break

//}else{

//$(this).parent().parent().siblings().find('.second-inp').prop("checked", true);

//}

}

//给第一层盒子加上选中

for(var j=0;j

if($(all[j]).prop("checked") == false){

$(this).parent().parent().parent().parent().find('.first-inp').prop("checked", false);

break ;

}else{

$(this).parent().parent().parent().parent().find('.first-inp').prop("checked", true);

}

}

});

//第二层反选

$(".per-index").click(function() {

var nb = $(this).parent().parent().parent().find('.per-index');

for(var i=0;i

if($(nb[i]).prop("checked") == false){

$(".first-inp").prop("checked", false);

return ;

}else {

$(".first-inp").prop("checked", true);

}

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
答案: 要实现全选反选功能,需要借助 JavaScript 实现。可以通过设定一个全选复选框,以及多个子复选框来实现全选反选的功能。 以下是一个实现全选反选的 JavaScript 代码示例: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>全选反选</title> <script type="text/javascript"> // 获取全选复选框和所有子复选框 var selectAll = document.getElementById("select-all"); var checkboxes = document.getElementsByName("checkbox"); // 全选复选框的事件处理函数 selectAll.onclick = function () { for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = selectAll.checked; } }; // 子复选框的事件处理函数 for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].onclick = function () { var checkedCount = 0; for (var j = 0; j < checkboxes.length; j++) { if (checkboxes[j].checked) { checkedCount++; } } selectAll.checked = (checkedCount == checkboxes.length); }; } </script> </head> <body> <input type="checkbox" id="select-all">全选<br> <input type="checkbox" name="checkbox">选项1<br> <input type="checkbox" name="checkbox">选项2<br> <input type="checkbox" name="checkbox">选项3<br> <input type="checkbox" name="checkbox">选项4<br> </body> </html> ``` 这段代码会在页面上生成一个全选复选框以及四个子复选框,点击全选时,所有子复选框都会被选;再次点击全选时,所有子复选框都会取消选。同时,每次点击子复选框时,全选复选框的状态会被更新。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值