javascript怎么获取表单类复选框的个数

来源:百度知道 编辑:UC知道 时间:2024/06/28 09:59:02
1.获取表单复选框的个数是用来做循环的,要怎么获取呢?
2.看
tr0.style.backgroundColor='white';
tr1.style.backgroundColor='white';
tr2.style.backgroundColor='white';
tr3.style.backgroundColor='white';
tr4.style.backgroundColor='white';

上面的其实用个循环,但怎么写?
对javascript不太熟悉,希望懂的人帮我下.谢谢 我再线等的,你的

1. var trlist=document.getElementsByTagName("input");
var checkedCount=0;
for(var i=0;i<trlist.length;i++)
{
if(trlist[i].type=="checkbox" && trlist[i].checked==true)
{
checkedCount++;
}
}
alert(checkedCount);

2. var trlist=document.getElementsByTagName("tr");
for(var i=0;i<trlist.length;i++)
{
trlist[i].style.backgroundColor='white';
}

for(intput type = checkbox){
if (checkbox[i].checked){ // 这个被选中了
tr[i].style.backgroundColor='white';
}else{
}
}