您现在的位置是:网站首页> 编程资料编程资料

jquery实现全选功能_jquery_

2023-05-24 382人已围观

简介 jquery实现全选功能_jquery_

本文实例为大家分享了jquery实现全选功能的具体代码,供大家参考,具体内容如下

话不多说,直接上代码:

html代码:

         
               
                  行业                
                   
                                                                        全部                  
         
         
               
                     电力                
           
                    钢铁            
           
                    电网            
           
                    化工            
           
                    石化            
           
                    造纸            
           
                    建材            
           
                    有色          
     

关键css代码:

.content-wrap-show .con .item-box .selectItem .selectActive::after {      content: '';      position: absolute;      width: 0.475rem;      height: 0.5rem;      background: url("../img/selectimg.svg")no-repeat;      background-size: 100% 100%;      display: inline-block;      *zoom: 1;      bottom: 0;      right: 0;  }  .content-wrap-show .con .item-box .selectItem .active {      border-color: #45FFF8;  }  .content-wrap-show .con .item-box .selectItem .selectActive {      position: relative;  }  #selectAll1+label {      width: .6rem;      height: .6rem;      border: 1px solid #293773 !important;      background-color: #0f1b52 !important;      display: inline-block;      *display: inline;      *zoom: 1;      position: relative;      top: 6px;      left: 0;      border-radius: 4px;      cursor: pointer;      overflow: hidden;  }  #selectAll1[type=checkbox] {      visibility: hidden;  }  #selectAll1+label{      z-index: 9;  }  #selectAll1:checked+label:before {      content: '\2713';      width: .45rem;      height: .45rem;      display: block;      color: #ffffff;      text-align: center;      font-weight: bolder;      position: absolute;      top: 0px;      left: 1px;  }

方法:

// 行业全选点击事件         $('#industrySelectAll>#selectAll1').click(function () {             $(this).toggleClass('active')             var hasClass = $(this).hasClass('active')             $('#industrySelectItem .itemSelect').each(function () {                 if (!hasClass) {                     $(this).removeClass('selectActive')                 } else {                     $(this).addClass('selectActive')                 }             })         });         // 行业复选点击事件         $("#industrySelectItem>div").click(function () {             $(this).toggleClass('active')             var hasClass = $(this).hasClass('active')             if (!hasClass) {                 $(this).removeClass('selectActive')             } else {                 $(this).addClass('selectActive')             }         });

效果如下:

需要注意的是input的id和label的for要保持一致!!!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

-六神源码网