網站首頁 編程語言 正文
本文實例為大家分享了jquery實現全選功能的具體代碼,供大家參考,具體內容如下
話不多說,直接上代碼:
html代碼:
<div class="item-box">
? ? ? ? ?<div class="item-title">
? ? ? ? ? ? ? ?<div class="titleBox">
? ? ? ? ? ? ? ? ? <span>行業</span>
? ? ? ? ? ? ? ?</div>
? ? ? ? ? ? ? ? ? ? <div class="select-all" id="industrySelectAll">
? ? ? ? ? ? ? ? ? ? ? ? <input type="checkbox" id="selectAll1">
? ? ? ? ? ? ? ? ? ? ? ? <label for="selectAll1"></label>
? ? ? ? ? ? ? ? ? ? ? ? <span>全部</span>
? ? ? ? ? ? ? ? ?</div>
? ? ? ? ? </div>
? ? ? ? ? <div class="tab-item selectItem" id="industrySelectItem">
? ? ? ? ? ? ? ?<div class="quotaItem itemSelect">
? ? ? ? ? ? ? ? ? ? ?<span>電力</span>
? ? ? ? ? ? ? ?</div>
? ? ? ? ? ?<div class="quotaItem itemSelect">
? ? ? ? ? ? ? ? ? ? <span>鋼鐵</span>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="quotaItem itemSelect">
? ? ? ? ? ? ? ? ? ? <span>電網</span>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="quotaItem itemSelect">
? ? ? ? ? ? ? ? ? ? <span>化工</span>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="quotaItem itemSelect">
? ? ? ? ? ? ? ? ? ? <span>石化</span>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="quotaItem itemSelect">
? ? ? ? ? ? ? ? ? ? <span>造紙</span>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="quotaItem itemSelect">
? ? ? ? ? ? ? ? ? ? <span>建材</span>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="quotaItem itemSelect">
? ? ? ? ? ? ? ? ? ? <span>有色</span>
? ? ? ? ? </div>
? ? ?</div>
</div>
關鍵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要保持一致!!!
原文鏈接:https://blog.csdn.net/HuLuWa1997/article/details/119808926
相關推薦
- 2022-03-15 3 Segmentation fault (core dumped) ./a.out Exited
- 2023-01-27 C#實現拆分合并Word表格中的單元格_C#教程
- 2023-07-15 express 連接 MongoDb
- 2022-05-13 Django-認證-權限控制-節流-分頁-過濾
- 2022-08-05 C語言文件操作之fread函數詳解_C 語言
- 2022-08-05 EasyExcel 3.X 簡單寫入Excel文件數據
- 2022-07-11 docker搭建redis 主從哨兵集群
- 2022-12-06 Android?SwipeRefreshLayout超詳細講解_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支