---
title: "全选反选"
author: "wyr123789"
date: "2017-05-09T18:34:41Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2017-05-09T18:34:35Z"
id: 2373471
url: "https://wyr123789.iteye.com/blog/2373471"
---

<div class="js_mobile">
	<input name="Fruit" type="checkbox" value="" />苹果  
	<input name="Fruit" type="checkbox" value="" />桃子  
	<input name="Fruit" type="checkbox" value="" />香蕉 
	<input name="Fruit" type="checkbox" value="" />梨  
</div>

<a class="js_all"><input name="Fruit" type="checkbox" value="" /> 全选</a>
<script type="text/javascript" src="../v4.0-js/plug/jquery.min.js"></script>
<script>
	$(".js_all").on('click',function(){
		var checktrue= $(".js_mobile :checkbox").size();
		var chk = 0;
		console.log('chk---'+chk);
		console.log('checktrue---'+checktrue);
		$(".js_mobile :checkbox").each(function () {  
	        if($('.js_all :checkbox').prop("checked")==true){
				chk++;
			}
	   	}); 
	   console.log('chk---aaa   '+chk);
		if(checktrue==chk){
			 $(".js_mobile :checkbox").prop("checked",true);
			return;
		}
			$(".js_mobile :checkbox").prop("checked",false);
	});
</script>