jquery全选 反选

//全选 反选
	$('#chkAll').on('click',function(){
		$('input.chkbox').prop('checked',$(this).prop('checked'));	
	});
	
	$('input.chkbox').on('click',function() {
		$('input.chkbox:checked').length == $('input.chkbox').length ? $('#chkAll').prop('checked',true):$('#chkAll').prop('checked',false);
	});
//获取选中checkbox的值
function chk(){
var obj=document.getElementsByName('chkbox'); //选择所有name="'test'"的对象,返回数组
//取到对象数组后,我们来循环检测它是不是被选中
var s='';
for(var i=0; i<obj.length; i++){
if(obj[i].checked) s+=obj[i].value+','; //如果选中,将value添加到变量s中
}
alert(s);
}

  

$("#"+id).prop("checked")==true //选中

  

原文地址:https://www.cnblogs.com/finnlee/p/4996630.html