搜尋
首頁php框架ThinkPHPthinkphp怎麼實作全選

thinkphp怎麼實作全選

Dec 08, 2022 am 09:42 AM
thinkphp

thinkphp實現全選的方法:1、建立一個前端範例文件,並設定html按鈕;2、透過js程式碼「layui.use('form', function () {...}」實現資料全部勾選;3、開啟thinkphp文件,透過「public function deleteAll(){...}」方法實現全選刪除操作即可。

thinkphp怎麼實作全選

# #本教學操作環境:Windows7系統、ThinkPHP5版、Dell G3電腦。

thinkphp怎麼實作全選?

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">
      $(&#39;#btndelete&#39;).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(&#39;请选择数据删除&#39;)}else{
        layer.confirm(&#39;确定要删除?&#39;, function(index) {
     
     
       window.location.href=&#39;/admin/commodity/deleteAll?b=&#39;+b;
        
      })}
    })
   </script>
    <!-- 全选框 -->
   <script type="text/javascript">
      layui.use(&#39;form&#39;, function () {
        var form = layui.form;
        //全选
        form.on(&#39;checkbox(c_all)&#39;, function (data) {
            var a = data.elem.checked;
            if (a == true) {
                $(".cityId").prop("checked", true);
                form.render(&#39;checkbox&#39;);
            } else {
                $(".cityId").prop("checked", false);
                form.render(&#39;checkbox&#39;);
            }
 
        });
        //反选
        form.on(&#39;checkbox(f_all)&#39;, function (data) {
            var item = $(".cityId");
            item.each(function () {
                if ($(this).prop("checked")) {
                    $(this).prop("checked", false);
                } else {
                    $(this).prop("checked", true);
                }
            })
            form.render(&#39;checkbox&#39;);
 
 
        });
        //有一个未选中全选取消选中
        form.on(&#39;checkbox(c_one)&#39;, 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(&#39;checkbox&#39;);
                    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(&#39;checkbox&#39;);}
        });
 
 
    });
   </script>

這個是跳到方法裡進行刪除

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

推薦學習:《

thinkPHP影片教學

以上是thinkphp怎麼實作全選的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)