当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - multiple set of check box?

问题描述:

im having a set of multiple check bxes, like one set contain 3 check box share same name another set contain 3 check sharing same name . how can i get the value of these two different set of check box using a single code .

 var form = $('usersurvey');

checkboxes = form.getInputs('checkbox');

for(count=0; count< checkboxes.length; count++){

if(checkboxes[count].checked){

retValue=true;

break;

}

}

return retValue;

}

im tried with this code but it fetch all the check boxes , i want only that have the same name, i used prototype.js

网友答案:

if you give each set of checkboxes a different class you could select them using jquery like:

$(".className").each(function(index, element) { ... }); 

for instance. somebody may be able to improve on this solution by selecting by name (i wasnt sure if you could do that, i always just select by class).

EDIT: sorry i should elaborate probably. the $(".className") piece will select all the checkboxes of class 'className'. since it sounds like you want to DO something with each of them though, i just added the each call on the end. inside the each call, you can define a function (shown) that will do something for each checkbox that was selected. reference the jquery each docs here:

http://api.jquery.com/each/

分享给朋友:
您可能感兴趣的文章:
随机阅读: