>  기사  >  PHP 프레임워크  >  thinkphp에서 모든 선택을 달성하는 방법

thinkphp에서 모든 선택을 달성하는 방법

藏色散人
藏色散人원래의
2022-12-08 09:42:041823검색

모든 선택을 수행하는 Thinkphp 방법: 1. 프런트 엔드 샘플 파일을 만들고 html 버튼을 설정합니다. 2. js 코드 "layui.use('form', function () {...}"를 사용하여 선택합니다. 모든 데이터 ;3. thinkphp 파일을 열고 "public function deleteAll(){...}" 메소드를 사용하여 모두 삭제하세요.

thinkphp에서 모든 선택을 달성하는 방법

이 튜토리얼의 운영 환경: Windows 7 시스템, ThinkPHP 버전 5 , 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으로 문의하세요.