網(wǎng)站首頁 編程語言 正文
本文實例為大家分享了jquery實現(xiàn)全選功能的具體代碼,供大家參考,具體內(nèi)容如下
話不多說,直接上代碼:
html代碼:
<div class="item-box">
? ? ? ? ?<div class="item-title">
? ? ? ? ? ? ? ?<div class="titleBox">
? ? ? ? ? ? ? ? ? <span>行業(yè)</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>電網(wǎng)</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>
關(guān)鍵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;
?}
方法:
// 行業(yè)全選點擊事件
? ? ? ? $('#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')
? ? ? ? ? ? ? ? }
? ? ? ? ? ? })
? ? ? ? });
? ? ? ? // 行業(yè)復選點擊事件
? ? ? ? $("#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
相關(guān)推薦
- 2022-09-30 Ajax實現(xiàn)關(guān)鍵字聯(lián)想和自動補全功能及遇到坑_AJAX相關(guān)
- 2022-04-18 python全面解析接口返回數(shù)據(jù)_python
- 2022-10-09 淺談Redis處理接口冪等性的兩種方案_Redis
- 2022-07-19 詳解的wc find xargs zip gzip bzip2 xz tar sftp命令或者協(xié)議
- 2023-12-02 浮動清除通用代碼
- 2022-05-13 Django-Rest framwork框架 序列化與反序列化
- 2023-01-27 goroutine?泄漏和避免泄漏實戰(zhàn)示例_Golang
- 2022-06-18 python使用Random隨機生成列表的方法實例_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支