JQuery checkbox的全选和反选

 学习笔记,转自:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.7.js"></script>
</head>
<script type="text/javascript">
$(function()
{
	$('input[name=orgType]').click(function() {
	var val = $(this).val();
	if(val=='') {
		checkAllSubType(this);
	}else{
	   
	}
  });
});
function checkAllSubType(obj){
	$('.checkAll').parents('li').nextAll().each(function(i){
		var $input = $(this).find('input[name=orgType]');
		$input.prop('checked',!$input.prop('checked'));
		
	});

	
}
</script>
<body>
<table>
<tr id="subType1" class="subType">
     <th>机构类型:</th>
    <td><div class="mexbox1">
      <ul id="jgxz">
      	<li><span class="pmr15"><input id="org_type_1" pid="1" name="orgType" type="checkbox" value="" class="checkAll">全部</span></li>
      	<li><span class="pmr15"><input id="org_type_11" name="orgType" type="checkbox" value="11">11</span></li>
      	<li><span class="pmr15"><input id="org_type_12" name="orgType" type="checkbox" value="12">12</span></li>
      	<li><span class="pmr15"><input id="org_type_13" name="orgType" type="checkbox" value="13">13</span></li>
      	<li><span class="pmr15"><input id="org_type_14" name="orgType" type="checkbox" value="14">14</span></li>
      </ul> 
      </div></td>
  </tr>
</table>
</body>
</html>

 

你可能感兴趣的:(checkbox)