奋斗中的小哥
2016-05-26 11:22
如果单选框全部选中,这个时候全选框也要被选中,这个如何实现?
也可以写个计数器count。每次选中一个单选框,则count++,当count ===tr.length,则设置全选当checked为true.
在每一个单选框的单击事件中,循环遍历每个单选框的状态,如果都是true,就将全选框置为true
//获取所有的单选框
var singleBoxs=getElementByClassName('single');
for(var i=0,len=singleBoxs;i<len;i++){
singleBoxs.onclick=function(){
var quanxuan=true;
for(var j=0,len=singleBoxs;j<len;j++){
quanxuan=quanxuan & this.checked;
}
if(quanxuan){
//获取全选框
var allBox=document.getElementByClassName('all');
allBox.checked=true;
}
}
}用JS实现购物车特效
43234 学习 · 176 问题
相似问题