简体   繁体   中英

jQuery selector for dynamic input name

I have a set of checkboxes that have a name like

form[check][..]

where .. is a number (id). I would have another checkbox that checked would check all the previous checkboxes, a sort of check/uncheck all. The problem is, how can with jQuery get all that checkboxes?

EDIT 1

this is my current html markup:

<input type="checkbox" value="1" name="form[check][1]" />
<input type="checkbox" value="1" name="form[check][2]" />
<input type="checkbox" value="1" name="form[check][3]" />
<input type="checkbox" value="1" name="form[check][..]" />

<input type="checkbox" name="checkAll" />

在要检查的复选框中添加一个类,然后使用该类选择它们

$('.myCheckbox').prop('checked', true);
$('[name="checkAll"]').on('change', function(){
    $('input[name^="form[check]"]:checkbox').prop('checked', $(this).prop('checked'));
});​

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM