0418 jQuery笔记(添加事件、each、prop、$(this))

1.添加点击事件、each、prop、$(this)

 1     //全选框的被动操作
 2     //定义一个标志保存最终状态
 3     var flag = false;
 4     //为每一个选择框添加点击事件,数组.click()
 5     $('.chex').click(function(){
 6         //遍历数组,数组.each()
 7         $('.chex').each(function(){
 8             //判断每一个元素的点击状态,$(this)当前元素
 9             if($(this).prop('checked')){
10                 flag = true;
11             }else{
12                 flag = false;
13                 //不可以使用break
14                 return false;
15             }
16         });
17         if(flag){
18             $('#chexAll').prop('checked',true);
19         }else{
20             $('#chexAll').prop('checked',false);
21         }
22     });
全选框的被动操作
原文地址:https://www.cnblogs.com/flypea93/p/8872414.html