以下为实现思路,已测试,供参考
var allSet = document.getElementById('allSet');//获取全选按钮元素
var a = allSet.Custom;//给全选按钮自定义属性
a = 0;//自定义属性值为0
var input1 = all.getElementsByTagName('input');//获取all下的全部input标签;
//给全选按钮添加点击事件,进行判断;
allSet.onclick = function() {
//如果a为0执行第一个for循环;
if(a == 0) {
//循环遍历所有input标签;
for(i = 0; i < input1.length; i++) {
//让input标签处于选中状态 (checked = true 选中),(checked = false 未选中);
input1[i].checked = true;
//在这里将自定义属性的值变为1
a = 1
}
}
//如果a为1执行下一个for循环,让input标签处于未选中状态
else{
for(i = 0; i < input1.length; i++) {
input1[i].checked = false;
a = 0
}
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有