是的,它是一个ID..
$('#checkbox') <-- refers to an element having an id as "checkbox" it might be div or checkbox or any element whose id is equal to checkbox.
$('.checkbox') <--refers to an element having class as "checkbox"
$('input:checkbox') <--- refers to all input with type checkbox
浏览文档以了解有关选择器的更多信息
更新
例子
$('#Container').append('<input type="checkbox" class="ckbox" id = '+ data[i].name + '/> ' + data[i].name + '<br />');
$('#Container').append('<input type="checkbox" class="ckbox" id = '+ data[i].name + '/> ' + data[i].name + '<br />');
调用类选择器
$('#Container').on('change','.ckbox',function(){
var selectedValue = $("input.ckbox:checked").map(function(n){
return this.value;
});
alert(seletedValue.join(','));
});
on()
因为检查是动态添加的,所以必须委托事件才能发生更改事件。