如何多选进行修改

如何在复选框勾选多个时,用id进行修改

第一步mappr里面

 UPDATE 表名 SET
         ????
        WHERE
            id in(
                <foreach item="item" index="index" collection="br_ids" open="(" separator="," close=")">
                    #{item}
                </foreach>
            ) //首先用in 然后用 Foreach

第二步页面Sricpt中

	//如何id是从后台传过来的
 (function ($) {
        let br_ids = $("#br_ids").val().split(",");
        $('#br_ids').val(br_ids);
        let checkboxes_all = $("input:checkbox");
        for (let i = 0; i < br_ids.length; i++) {
            checkboxes_all.each(function () {
                if ($(this).val() === br_ids[i]) {
                    $(this).prop("checked", true);
                }
            });
        }
        let checkboxes_checked = $("input[type='checkbox'][name='checkboxes']:checked");
        if (checkboxes_checked.length !== 0 && checkboxes_checked.length === checkboxes_all.length - 1) {
            $('#select_all_checked').prop("checked", true);
        }
    })(jQuery);
	//控制全选选择框
   function selectAll() {
       let select_all_checked = $('#select_all_checked').is(':checked');
       let checked = $("#br_ids").val().split(",");
       let checked_list = $('input:checkbox');
       if (select_all_checked === true) {
           for (let i = 0; i < checked.length; i++) {
               checked_list.each(function () {
                   $(this).prop("checked", false)
                   if ($(this).val() !== 'on' && checked[i] == $(this).val()) {
                       checked.splice(i, 1);
                   }
               });
           }
           checked_list.each(function () {
               $(this).prop("checked", true)
               if ($(this).val() !== 'on') {
                   checked.push($(this).val());
               }
           });
       } else {
           for (let i = 0; i < checked.length; i++) {
               checked_list.each(function () {
                   $(this).prop("checked", false)
                   if ($(this).val() !== 'on' && checked[i] == $(this).val()) {
                       checked.splice(i, 1);
                   }
               });
           }
       }
       $('#br_ids').val(checked);
   }
   //单个复选框控制选中
   function checkboxes_clicks(br_id) {
       let br_ids = $("#br_ids").val().split(",");
       let checkboxes_checked = $("input[type='checkbox'][name='checkboxes']:checked");
       let checkboxes_all = $("input:checkbox");
       let isAdd = false;
       checkboxes_checked.each(function () {
           if ($(this).val() == br_id) {
               isAdd = true;
           }
       });
       if (isAdd) {
           console.log(br_id);
           br_ids.push(br_id);
       } else {
           for (let i = 0; i < br_ids.length; i++) {
               if (br_ids[i] == br_id) {
                   br_ids.splice(i, 1);
               }
           }
       }
       $('#br_ids').val(br_ids);
       if (checkboxes_checked.length !== 0 && checkboxes_checked.length !== checkboxes_all.length - 1) {
           $("#select_all_checked").prop("checked", false);
       }
       if (checkboxes_checked.length !== 0 && checkboxes_checked.length === checkboxes_all.length - 1) {
           $('#select_all_checked').prop("checked", true);
       }
   }

第三步页面body中

//表格单元格
 <input type="checkbox" name="checkboxes" class="checkboxes" onclick="checkboxes_clicks(${bookRenew.br_id})"value="${bookRenew.br_id}" style=""/> 
 //表格头部控制全选
<input type="checkbox" id="select_all_checked" class="group-checkable" data-set="#sample_1 .checkboxes" onclick="selectAll()" style="position: relative;top: 10px"/>
//隐藏文本框
<input id="br_ids" type="hidden" name="br_ids“  value="${params.br_ids}"/>

第四步页面body中运行

 let br_ids= $("#br_ids").val().split(",");
        for (let i = 0; i < br_ids.length; i++) {
            if (br_ids[i] == "") {
                br_ids.splice(i, 1);
            }
        }
        if (br_ids.length == 0) {
            alert("您未勾选任何选项项!");
            return;
        }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值