2013-04-05 64 views
0

我目前使用下面的代码循环复选框。它的工作原理,但它是让我的网页上的每一个复选框。有没有办法只选择共享相同的名称,类,或存在于同一个div容器中的某一组复选框?选择复选框作为一组

感谢

$('input[type=checkbox]').each(function() { 
...do stuff 

回答

2

过滤的名字:

$('input[type=checkbox][name=yourname]') 

$('input[type=checkbox]').filter('[name=yourname]') 

过滤通过类

$('input[type=checkbox]').filter('.myclass') 

滤波由父:

$('input[type=checkbox]', parent) 
2

在同一div(假定它有一个类):

$('.theclassofthediv input[type=checkbox]').each(function() { 
2

滤波器按名称:

$('input[type=checkbox][name=name]') 

滤波器由类

$('input[type=checkbox]').filter('.myclass').each(..) 
1

Filtering by类,直接在选择器中不使用.filter()

$('input.myclass[type=checkbox]');