コード:
<div>
<input type='checkbox' lid='1'><label>checkbox1</label>
<input type='checkbox' lid='2'><label>checkbox1</label>
<input type='checkbox' lid='3'><label>checkbox1</label>
<input type='checkbox' lid='4'><label>checkbox1</label>
</div>
<script type='text/javascript'>
var arr = new Array("1", "2");
$('input[type=checkbox]').each(function(){
$.inArray($(this).attr('lid'), arr){
$(this).attr('checked','checked')
}
});
</script>
配列内のアイテムと同じ「ふた」を持つすべてのチェックボックスをチェックしようとしています。現在、私の関数はすべてのチェックボックスをチェックしています。