CheckBox全选

这里写图片描述
这里实现的效果是:
当点击选择的时候,显示一个div,上面有许多checkbox,
当点击全选的时候,会选中所有的checkbox。
遇到的问题:
在使用Jquery的attr做属性设置的时候,第一次全选和取消全选起作用,之后就不起作用,修复方法,使用prop函数。
具体如下:
这里写图片描述

<td class='tdEr' style="position:relative" id="InterType">
                            <div id="TypeSelect" 
                            style="cursor:pointer;width:100px;background:#CBC9C5;text-align:center;border-radius:5px;">选择</div>
                            <div id="TypeDialog" 
                            style="width:200px;position:absolute;left:10px;top:30px;background:#DFDFDC;border-radius:10px;
                                padding-left:10px;padding-top:10px;border:1px solid #C4C4C2;">
                            </div>  
                            </div>
                         </td>

//选择接口类型
(“#TypeSelect”).click(function(){.ajax({
url: ‘${root}/statisticalAnalysis/002/listAllInterType.do’,
type : ‘post’,
data:{},
dataType : ‘text’,
success : function(data){
var dataStr=data.substr(1,data.length-2);
var arr=dataStr.split(“,”);

                    var str='';
                    str+='<input id="checkAll" type="checkbox" style="margin:0 5px 0 10px;"/>';
                    str+='<label for="checkAll">[@s.m 'allSelect'/]</label><br/>';
                    for(var i=0;i<arr.length;i++){
                        str+='<input id="abc'+i+'" type="checkbox" name="interType" value="'+arr[i].trim()+'" style="margin:0 5px 0 10px;"/>';
                        str+='<label for="abc'+i+'">'+arr[i].trim()+'</label>';
                        str+="<br/>";
                    }
                    str+='<input type="button" value="[@s.m 'confirm2'/]" class="inputTwo inputQuery"  id="confirmBut" style="position:absolute;bottom:5px;right:20px;"/>';

                    $("#TypeDialog").empty();
                    $("#TypeDialog").append(str);
                    if(flag){
                        $("#TypeDialog").height($("#TypeDialog").height()+35);
                        flag=false;
                    }
                    $("#TypeDialog").show();

                    $("#confirmBut").click(function(){
                        $("#TypeDialog").hide();
                     });

                    $("#checkAll").click(function(){
                        if($('#checkAll').is(':checked')) {
                            $("#TypeDialog input[type='checkbox']").prop("checked",true);//注意这里
                        }else{
                            $("#TypeDialog input[type='checkbox']").prop("checked",false);
                        }
                    });
                },
                 error : function(data){
                    alert("[@s.m 'notice103'/]");
                 }
             });
      });
  })

“`
当点击”选择”的时候,会发送ajax请求到后台加载checkbox的内容,这里代码有关于业务,标签是freemarker的,就不做过多解释,然后将后台获取到的数据做拼接后动态添加到DIV弹出框中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值