温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

thinkphp如何实现全选功能

发布时间:2022-12-08 10:38:59 来源:亿速云 阅读:106 作者:iii 栏目:编程语言

这篇“thinkphp如何实现全选功能”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“thinkphp如何实现全选功能”文章吧。

thinkphp实现全选的方法:1、创建一个前端示例文件,并设置html按钮;2、通过js代码“layui.use('form', function () {...}”实现数据全部勾选;3、打开thinkphp文件,通过“public function deleteAll(){...}”方法实现全选删除操作即可。

thinphp5+html全选和反选和多选后删除

最近研究了下按钮的多选,大家可以看看,话不多说上代码

html按钮

      <input style="float: right;margin-left: 10px" type="checkbox" lay-skin="primary"  id="c_all" lay-filter="c_all" title="全部">
      <input style="float: right;margin-left: 10px" type="checkbox" lay-skin="primary"  id="f_all" lay-filter="f_all" title="反选">    
      <input style="float:right;margin-top: 3.5px;margin-left:10px" type="button" id="btndelete" class="layui-btn layui-btn-sm" value="删除">

js

 <!-- 多选删除 -->
    <script type="text/javascript">
      $('#btndelete').click(function(){
       var a = document.getElementsByName("cityId");
        var b=[];
       for(i in a){
         if(a[i].checked)
           b.push(a[i].value);
       }
       if(b==""){alert('请选择数据删除')}else{
        layer.confirm('确定要删除?', function(index) {
     
     
       window.location.href='/admin/commodity/deleteAll?b='+b;
        
      })}
    })
   </script>
    <!-- 全选框 -->
   <script type="text/javascript">
      layui.use('form', function () {
        var form = layui.form;
        //全选
        form.on('checkbox(c_all)', function (data) {
            var a = data.elem.checked;
            if (a == true) {
                $(".cityId").prop("checked", true);
                form.render('checkbox');
            } else {
                $(".cityId").prop("checked", false);
                form.render('checkbox');
            }
 
        });
        //反选
        form.on('checkbox(f_all)', function (data) {
            var item = $(".cityId");
            item.each(function () {
                if ($(this).prop("checked")) {
                    $(this).prop("checked", false);
                } else {
                    $(this).prop("checked", true);
                }
            })
            form.render('checkbox');
 
 
        });
        //有一个未选中全选取消选中
        form.on('checkbox(c_one)', function (data) {
            var item = $(".cityId");
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked == false) {
                    $("#c_all").prop("checked", false);
                    form.render('checkbox');
                    break;
                }
            }
            //如果都勾选了  勾上全选
            var  all=item.length;
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked == true) {
                    all--;
                }
            }
            if(all==0){
            $("#c_all").prop("checked", true);
            form.render('checkbox');}
        });
 
 
    });
   </script>

这个是跳到方法里进行删除

    // 删除全部
    public function deleteAll(){
            $b=input('b');
            // Db::name('excel')->where('id','in',$b)->delete();
            if(false == Db::name('commodity')->where('id','in',$b)->delete()) {
                return $this->error('删除失败,请选择要删除的数据');
            } else {
               
                return $this->success('删除成功','admin/commodity/index');
            }    
    }

以上就是关于“thinkphp如何实现全选功能”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI