购物车全选 和取消功能

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>购物车 全选</title>
<script src="http://www.aniu.tv/Public/Common/js/jquery.min.js"></script>
</head>
<script type="text/javascript">
$(function(){
$('.all').click(function(){
if($('.all').is(':checked')){
$('.check').prop('checked',true);
}else{
$('.check').prop('checked',false);

});
$('.check').click(function(){
var i = 0;
var arr = $('.check').length;
$('.check').each(function(){
if($(this).is(':checked')){
i++;
};
});
if(i == arr){
$('.all').prop('checked',true);
}else{
$('.all').prop('checked',false);
}

});
});
</script>
</head>
<body>
<input class="all" type="checkbox" id="selectAll">全选
<input class="check" type="checkbox">
<input class="check" type="checkbox">
<input class="check" type="checkbox"> 
</body>
</html>

原文地址:https://www.cnblogs.com/yuejiaming/p/6496999.html