前端学习条记-Web APIs篇-02

[复制链接]
发表于 2026-1-28 18:34:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
变乱监听(绑定)

什么是变乱?
变乱是在编程时体系内发生的动作大概发生的变乱【比如用户在网页上单击一个按钮 】
什么是变乱监听?
就是让步调检测是否有变乱产生,一旦有变乱触发,就立即调用一个函数做出相应,也称为绑定变乱大概注册变乱【比如鼠标颠末体现下拉菜单,比如点击可以播放轮播图等等】
  1. 元素对象.addEventListener('事件类型',要执行的函数)
复制代码
变乱监听三要素


  • 变乱源: 谁人dom元素被变乱触发了,要获取dom元素
  • 变乱范例: 用什么方式触发,比如鼠标单击 click、鼠标颠末 mouseover 等
  • 变乱调用的函数: 要做什么事 

随机问答案例 

业务分析:

  • ① 点击开始按钮随机抽取数组的一个数据,放到页面中
  • ② 点击竣事按钮删除数组当前抽取的一个数据
  • ③ 当抽取到末了一个数据的时间,两个按钮同时禁用(写点开始内里,只剩末了一个数据不消抽了 )
核心:使用定时器快速展示,制止定时器竣事展示 
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7.     <style>
  8.         * {
  9.             margin: 0;
  10.             padding: 0;
  11.         }
  12.         h2 {
  13.             text-align: center;
  14.         }
  15.         .box {
  16.             width: 600px;
  17.             margin: 50px auto;
  18.             display: flex;
  19.             font-size: 25px;
  20.             line-height: 40px;
  21.         }
  22.         .qs {
  23.             width: 450px;
  24.             height: 40px;
  25.             color: red;
  26.         }
  27.         .btns {
  28.             text-align: center;
  29.         }
  30.         .btns button {
  31.             width: 120px;
  32.             height: 35px;
  33.             margin: 0 50px;
  34.         }
  35.     </style>
  36. </head>
  37. <body>
  38.     <h2>随机点名</h2>
  39.     <div class="box">
  40.         <span>名字是:</span>
  41.         <div class="qs">这里显示姓名</div>
  42.     </div>
  43.     <div class="btns">
  44.         <button class="start">开始</button>
  45.         <button class="end">结束</button>
  46.     </div>
  47.     <script>
  48.         // 数据数组
  49.         const arr = ['马超', '黄忠', '赵云', '关羽', '张飞']
  50.         // 定时器的全局变量
  51.         let timerId = 0
  52.         // 随机号要全局变量
  53.         let random = 0
  54.         // 业务1.开始按钮模块
  55.         const qs = document.querySelector('.qs')
  56.         // 1.1 获取开始按钮对象
  57.         const start = document.querySelector('.start')
  58.         // 1.2 添加点击事件
  59.         start.addEventListener('click', function () {
  60.             timerId = setInterval(function () {
  61.                 // 随机数
  62.                 random = parseInt(Math.random() * arr.length)
  63.                 // console.log(arr[random])
  64.                 qs.innerHTML = arr[random]
  65.             }, 35)
  66.             // 如果数组里面只有一个值了,还需要抽取吗?  不需要  让两个按钮禁用就可以
  67.             if (arr.length === 1) {
  68.                 // start.disabled = true
  69.                 // end.disabled = true
  70.                 start.disabled = end.disabled = true
  71.             }
  72.         })
  73.         // 2. 关闭按钮模块
  74.         const end = document.querySelector('.end')
  75.         end.addEventListener('click', function () {
  76.             clearInterval(timerId)
  77.             // 结束了,可以删除掉当前抽取的那个数组元素
  78.             arr.splice(random, 1)
  79.             console.log(arr)
  80.         })
  81.     </script>
  82. </body>
  83. </html>
复制代码
变乱监听版本 

DOM L0         变乱源.on变乱 = function() { }
DOM L2         变乱源.addEventListener(变乱, 变乱处置处罚函数)
区别: on方式会被覆盖,addEventListener方式可绑定多次,拥有变乱更多特性,保举使用
发展史:
DOM L0 :是 DOM 的发展的第一个版本; L:level
DOM L1:DOM级别1 于1998年10月1日成为W3C保举尺度
DOM L2:使用addEventListener注册变乱
DOM L3: DOM3级变乱模块在DOM2级变乱的底子上重新界说了这些变乱,也添加了一些新变乱范例

变乱范例


 鼠标变乱



案例一:
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8" />
  5.   <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7.   <title>轮播图点击切换</title>
  8.   <style>
  9.     * {
  10.       box-sizing: border-box;
  11.     }
  12.     .slider {
  13.       width: 560px;
  14.       height: 400px;
  15.       overflow: hidden;
  16.     }
  17.     .slider-wrapper {
  18.       width: 100%;
  19.       height: 320px;
  20.     }
  21.     .slider-wrapper img {
  22.       width: 100%;
  23.       height: 100%;
  24.       display: block;
  25.     }
  26.     .slider-footer {
  27.       height: 80px;
  28.       background-color: rgb(100, 67, 68);
  29.       padding: 12px 12px 0 12px;
  30.       position: relative;
  31.     }
  32.     .slider-footer .toggle {
  33.       position: absolute;
  34.       right: 0;
  35.       top: 12px;
  36.       display: flex;
  37.     }
  38.     .slider-footer .toggle button {
  39.       margin-right: 12px;
  40.       width: 28px;
  41.       height: 28px;
  42.       appearance: none;
  43.       border: none;
  44.       background: rgba(255, 255, 255, 0.1);
  45.       color: #fff;
  46.       border-radius: 4px;
  47.       cursor: pointer;
  48.     }
  49.     .slider-footer .toggle button:hover {
  50.       background: rgba(255, 255, 255, 0.2);
  51.     }
  52.     .slider-footer p {
  53.       margin: 0;
  54.       color: #fff;
  55.       font-size: 18px;
  56.       margin-bottom: 10px;
  57.     }
  58.     .slider-indicator {
  59.       margin: 0;
  60.       padding: 0;
  61.       list-style: none;
  62.       display: flex;
  63.       align-items: center;
  64.     }
  65.     .slider-indicator li {
  66.       width: 8px;
  67.       height: 8px;
  68.       margin: 4px;
  69.       border-radius: 50%;
  70.       background: #fff;
  71.       opacity: 0.4;
  72.       cursor: pointer;
  73.     }
  74.     .slider-indicator li.active {
  75.       width: 12px;
  76.       height: 12px;
  77.       opacity: 1;
  78.     }
  79.   </style>
  80. </head>
  81. <body>
  82.   <div class="slider">
  83.     <div class="slider-wrapper">
  84.       <img src="./images/slider01.jpg" alt="" />
  85.     </div>
  86.     <div class="slider-footer">
  87.       <p>对人类来说会不会太超前了?</p>
  88.       <ul class="slider-indicator">
  89.         <li class="active"></li>
  90.         <li></li>
  91.         <li></li>
  92.         <li></li>
  93.         <li></li>
  94.         <li></li>
  95.         <li></li>
  96.         <li></li>
  97.       </ul>
  98.       <div class="toggle">
  99.         <button class="prev">&lt;</button>
  100.         <button class="next">&gt;</button>
  101.       </div>
  102.     </div>
  103.   </div>
  104.   <script>
  105.     // 1. 初始数据
  106.     const data = [
  107.       { url: './images/slider01.jpg', title: '对人类来说会不会太超前了?', color: 'rgb(100, 67, 68)' },
  108.       { url: './images/slider02.jpg', title: '开启剑与雪的黑暗传说!', color: 'rgb(43, 35, 26)' },
  109.       { url: './images/slider03.jpg', title: '真正的jo厨出现了!', color: 'rgb(36, 31, 33)' },
  110.       { url: './images/slider04.jpg', title: '李玉刚:让世界通过B站看到东方大国文化', color: 'rgb(139, 98, 66)' },
  111.       { url: './images/slider05.jpg', title: '快来分享你的寒假日常吧~', color: 'rgb(67, 90, 92)' },
  112.       { url: './images/slider06.jpg', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },
  113.       { url: './images/slider07.jpg', title: '一站式解决你的电脑配置问题!!!', color: 'rgb(53, 29, 25)' },
  114.       { url: './images/slider08.jpg', title: '谁不想和小猫咪贴贴呢!', color: 'rgb(99, 72, 114)' },
  115.     ]
  116.     // 获取元素
  117.     const img = document.querySelector('.slider-wrapper img')
  118.     const p = document.querySelector('.slider-footer p')
  119.     const footer = document.querySelector('.slider-footer')
  120.     // 1. 右按钮业务
  121.     // 1.1 获取右侧按钮
  122.     const next = document.querySelector('.next')
  123.     let i = 0  // 信号量 控制播放图片张数
  124.     // 1.2 注册点击事件
  125.     next.addEventListener('click', function () {
  126.       // console.log(11)
  127.       i++
  128.       // 1.6判断条件  如果大于8 就复原为 0
  129.       // if (i >= 8) {
  130.       //   i = 0
  131.       // }
  132.       i = i >= data.length ? 0 : i
  133.       // 1.3 得到对应的对象
  134.       // console.log(data[i])
  135.       // 调用函数
  136.       toggle()
  137.     })
  138.     // 2. 左侧按钮业务
  139.     // 2.1 获取左侧按钮
  140.     const prev = document.querySelector('.prev')
  141.     // 1.2 注册点击事件
  142.     prev.addEventListener('click', function () {
  143.       i--
  144.       // 判断条件  如果小于0  则爬到最后一张图片索引号是 7
  145.       // if (i < 0) {
  146.       //   i = 7
  147.       // }
  148.       i = i < 0 ? data.length - 1 : i
  149.       // 1.3 得到对应的对象
  150.       // console.log(data[i])
  151.       // 调用函数
  152.       toggle()
  153.     })
  154.     // 声明一个渲染的函数作为复用
  155.     function toggle() {
  156.       // 1.4 渲染对应的数据
  157.       img.src = data[i].url
  158.       p.innerHTML = data[i].title
  159.       footer.style.backgroundColor = data[i].color
  160.       // 1.5 更换小圆点    先移除原来的类名, 当前li再添加 这个 类名
  161.       document.querySelector('.slider-indicator .active').classList.remove('active')
  162.       document.querySelector(`.slider-indicator li:nth-child(${i + 1})`).classList.add('active')
  163.     }
  164.     // 3. 自动播放模块
  165.     let timerId = setInterval(function () {
  166.       // 利用js自动调用点击事件  click()  一定加小括号调用函数
  167.       next.click()
  168.     }, 1000)
  169.     // 4. 鼠标经过大盒子,停止定时器
  170.     const slider = document.querySelector('.slider')
  171.     // 注册事件
  172.     slider.addEventListener('mouseenter', function () {
  173.       // 停止定时器
  174.       clearInterval(timerId)
  175.     })
  176.     // 5. 鼠标离开大盒子,开启定时器
  177.     // 注册事件
  178.     slider.addEventListener('mouseleave', function () {
  179.       // 停止定时器
  180.       if (timerId) clearInterval(timerId)
  181.       // 开启定时器
  182.       timerId = setInterval(function () {
  183.         // 利用js自动调用点击事件  click()  一定加小括号调用函数
  184.         next.click()
  185.       }, 1000)
  186.     })
  187.   </script>
  188. </body>
  189. </html>
复制代码
核心变乱 


 
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Document</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.             box-sizing: border-box;
  13.         }
  14.         ul {
  15.             list-style: none;
  16.         }
  17.         .mi {
  18.             position: relative;
  19.             width: 223px;
  20.             margin: 100px auto;
  21.         }
  22.         .mi input {
  23.             width: 223px;
  24.             height: 48px;
  25.             padding: 0 10px;
  26.             font-size: 14px;
  27.             line-height: 48px;
  28.             border: 1px solid #e0e0e0;
  29.             outline: none;
  30.         }
  31.         .mi .search {
  32.             border: 1px solid #ff6700;
  33.         }
  34.         .result-list {
  35.             display: none;
  36.             position: absolute;
  37.             left: 0;
  38.             top: 48px;
  39.             width: 223px;
  40.             border: 1px solid #ff6700;
  41.             border-top: 0;
  42.             background: #fff;
  43.         }
  44.         .result-list a {
  45.             display: block;
  46.             padding: 6px 15px;
  47.             font-size: 12px;
  48.             color: #424242;
  49.             text-decoration: none;
  50.         }
  51.         .result-list a:hover {
  52.             background-color: #eee;
  53.         }
  54.     </style>
  55. </head>
  56. <body>
  57.     <div class="mi">
  58.         <input type="search" placeholder="小米笔记本">
  59.         <ul class="result-list">
  60.             <li><a href="#">全部商品</a></li>
  61.             <li><a href="#">小米11</a></li>
  62.             <li><a href="#">小米10S</a></li>
  63.             <li><a href="#">小米笔记本</a></li>
  64.             <li><a href="#">小米手机</a></li>
  65.             <li><a href="#">黑鲨4</a></li>
  66.             <li><a href="#">空调</a></li>
  67.         </ul>
  68.     </div>
  69.     <script>
  70.         // 1. 获取元素
  71.         const input = document.querySelector('[type=search]')
  72.         const ul = document.querySelector('.result-list')
  73.         // console.log(input)
  74.         // 2. 监听事件 获得焦点
  75.         input.addEventListener('focus', function () {
  76.             // ul显示
  77.             ul.style.display = 'block'
  78.             // 添加一个带有颜色边框的类名
  79.             input.classList.add('search')
  80.         })
  81.         // 3. 监听事件 失去焦点
  82.         input.addEventListener('blur', function () {
  83.             ul.style.display = 'none'
  84.             input.classList.remove('search')
  85.         })
  86.     </script>
  87. </body>
  88. </html>
复制代码
 键盘变乱&文本事件


案例:批评字数统计
需求:用户输入笔墨,可以盘算用户输入的字数
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.   <title>评论回车发布</title>
  8.   <style>
  9.     .wrapper {
  10.       min-width: 400px;
  11.       max-width: 800px;
  12.       display: flex;
  13.       justify-content: flex-end;
  14.     }
  15.     .avatar {
  16.       width: 48px;
  17.       height: 48px;
  18.       border-radius: 50%;
  19.       overflow: hidden;
  20.       background: url(./images/avatar.jpg) no-repeat center / cover;
  21.       margin-right: 20px;
  22.     }
  23.     .wrapper textarea {
  24.       outline: none;
  25.       border-color: transparent;
  26.       resize: none;
  27.       background: #f5f5f5;
  28.       border-radius: 4px;
  29.       flex: 1;
  30.       padding: 10px;
  31.       transition: all 0.5s;
  32.       height: 30px;
  33.     }
  34.     .wrapper textarea:focus {
  35.       border-color: #e4e4e4;
  36.       background: #fff;
  37.       height: 50px;
  38.     }
  39.     .wrapper button {
  40.       background: #00aeec;
  41.       color: #fff;
  42.       border: none;
  43.       border-radius: 4px;
  44.       margin-left: 10px;
  45.       width: 70px;
  46.       cursor: pointer;
  47.     }
  48.     .wrapper .total {
  49.       margin-right: 80px;
  50.       color: #999;
  51.       margin-top: 5px;
  52.       opacity: 0;
  53.       transition: all 0.5s;
  54.     }
  55.     .list {
  56.       min-width: 400px;
  57.       max-width: 800px;
  58.       display: flex;
  59.     }
  60.     .list .item {
  61.       width: 100%;
  62.       display: flex;
  63.     }
  64.     .list .item .info {
  65.       flex: 1;
  66.       border-bottom: 1px dashed #e4e4e4;
  67.       padding-bottom: 10px;
  68.     }
  69.     .list .item p {
  70.       margin: 0;
  71.     }
  72.     .list .item .name {
  73.       color: #FB7299;
  74.       font-size: 14px;
  75.       font-weight: bold;
  76.     }
  77.     .list .item .text {
  78.       color: #333;
  79.       padding: 10px 0;
  80.     }
  81.     .list .item .time {
  82.       color: #999;
  83.       font-size: 12px;
  84.     }
  85.   </style>
  86. </head>
  87. <body>
  88.   <div class="wrapper">
  89.     <i class="avatar"></i>
  90.     <textarea id="tx" placeholder="发一条友善的评论" rows="2" maxlength="200"></textarea>
  91.     <button>发布</button>
  92.   </div>
  93.   <div class="wrapper">
  94.     <span class="total">0/200字</span>
  95.   </div>
  96.   <div class="list">
  97.     <div class="item" style="display: none;">
  98.       <i class="avatar"></i>
  99.       <div class="info">
  100.         <p class="name">清风徐来</p>
  101.         <p class="text">大家都辛苦啦,感谢各位大大的努力,能圆满完成真是太好了[笑哭][支持]</p>
  102.         <p class="time">2022-10-10 20:29:21</p>
  103.       </div>
  104.     </div>
  105.   </div>
  106.   <script>
  107.     const tx = document.querySelector('#tx')
  108.     const total = document.querySelector('.total')
  109.     const item = document.querySelector('.item')
  110.     const text = document.querySelector('.text')
  111.     // 1. 当我们文本域获得了焦点,就让 total 显示出来
  112.     tx.addEventListener('focus', function () {
  113.       total.style.opacity = 1
  114.     })
  115.     // 2. 当我们文本域失去了焦点,就让 total 隐藏出来
  116.     tx.addEventListener('blur', function () {
  117.       total.style.opacity = 0
  118.     })
  119.     // 3. 检测用户输入
  120.     tx.addEventListener('input', function () {
  121.       // console.log(tx.value.length)  得到输入的长度
  122.       total.innerHTML = `${tx.value.length}/200字`
  123.     })
  124.     // 4. 按下回车发布评论
  125.     tx.addEventListener('keyup', function (e) {
  126.       // 只有按下的是回车键,才会触发
  127.       // console.log(e.key)
  128.       if (e.key === 'Enter') {
  129.         // 如果用户输入的不为空就显示和打印
  130.         if (tx.value.trim()) {
  131.           // console.log(11)
  132.           item.style.display = 'block'
  133.           // console.log(tx.value)  // 用户输入的内容
  134.           text.innerHTML = tx.value
  135.         }
  136.         // 等我们按下回车,结束,清空文本域
  137.         tx.value = ''
  138.         // 按下回车之后,就要把 字符统计 复原
  139.         total.innerHTML = '0/200字'
  140.       }
  141.     })
  142.   </script>
  143. </body>
  144. </html>
复制代码
 
变乱对象


变乱对象是什么

也是个对象,这个对象里有变乱触发时的干系信息 【比方:鼠标点击变乱中,变乱对象就存了鼠标点在哪个位置等信息】
使用场景

  • 可以判定用户按下哪个键,比如按下回车键可以发布消息
  • 可以判定鼠标点击了哪个元素,从而做相应的使用 
获取变乱对象

语法:怎样获取
在变乱绑定的回调函数的第一个参数就是变乱对象
一样平常定名为event、ev、e 

变乱对象常用属性 

部门常用属性 

  • type【获取当前的变乱范例】
  • clientX/clientY【获取光标相对于欣赏器可见窗口左上角的位置】
  • offsetX/offsetY【获取光标相对于当前DOM元素左上角的位置】
  • key【用户按下的键盘键的值,现在不提倡使用keyCode】
 

环境对象


环境对象:指的是函数内部特别的变量 this ,它代表着当前函数运行时所处的环境
作用:弄清晰this的指向,可以让我们代码更简便
函数的调用方式差别,this 指代的对象也差别
【谁调用, this 就是谁】 是判定 this 指向的大略规则
直接调用函数,着实相当于是 window.函数,以是 this 指代 window

回调函数


假如将函数 A 做为参数转达给函数 B 时,我们称函数 A 为回调函数
简单明白:当一个函数当做参数来转达给别的一个函数的时间,这个函数就是回调函数
常见的使用场景:


  • 把函数当做别的一个函数的参数转达,这个函数就叫回调函数
  • 回调函数本质照旧函数,只不外把它当成参数使用
  • 使用匿名函数做为回调函数比力常见 

综合案例



 
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8" />
  5.   <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7.   <title>tab栏切换</title>
  8.   <style>
  9.     * {
  10.       margin: 0;
  11.       padding: 0;
  12.     }
  13.     .tab {
  14.       width: 590px;
  15.       height: 340px;
  16.       margin: 20px;
  17.       border: 1px solid #e4e4e4;
  18.     }
  19.     .tab-nav {
  20.       width: 100%;
  21.       height: 60px;
  22.       line-height: 60px;
  23.       display: flex;
  24.       justify-content: space-between;
  25.     }
  26.     .tab-nav h3 {
  27.       font-size: 24px;
  28.       font-weight: normal;
  29.       margin-left: 20px;
  30.     }
  31.     .tab-nav ul {
  32.       list-style: none;
  33.       display: flex;
  34.       justify-content: flex-end;
  35.     }
  36.     .tab-nav ul li {
  37.       margin: 0 20px;
  38.       font-size: 14px;
  39.     }
  40.     .tab-nav ul li a {
  41.       text-decoration: none;
  42.       border-bottom: 2px solid transparent;
  43.       color: #333;
  44.     }
  45.     .tab-nav ul li a.active {
  46.       border-color: #e1251b;
  47.       color: #e1251b;
  48.     }
  49.     .tab-content {
  50.       padding: 0 16px;
  51.     }
  52.     .tab-content .item {
  53.       display: none;
  54.     }
  55.     .tab-content .item.active {
  56.       display: block;
  57.     }
  58.   </style>
  59. </head>
  60. <body>
  61.   <div class="tab">
  62.     <div class="tab-nav">
  63.       <h3>每日特价</h3>
  64.       <ul>
  65.         <li><a class="active" href="javascript:;">精选</a></li>
  66.         <li><a href="javascript:;">美食</a></li>
  67.         <li><a href="javascript:;">百货</a></li>
  68.         <li><a href="javascript:;">个护</a></li>
  69.         <li><a href="javascript:;">预告</a></li>
  70.       </ul>
  71.     </div>
  72.     <div class="tab-content">
  73.       <div class="item active"><img src="./images/tab00.png" alt="" /></div>
  74.       <div class="item"><img src="./images/tab01.png" alt="" /></div>
  75.       <div class="item"><img src="./images/tab02.png" alt="" /></div>
  76.       <div class="item"><img src="./images/tab03.png" alt="" /></div>
  77.       <div class="item"><img src="./images/tab04.png" alt="" /></div>
  78.     </div>
  79.   </div>
  80.   <script>
  81.     // 1. a 模块制作 要给 5个链接绑定鼠标经过事件
  82.     // 1.1 获取 a 元素
  83.     const as = document.querySelectorAll('.tab-nav a')
  84.     // console.log(as)
  85.     for (let i = 0; i < as.length; i++) {
  86.       // console.log(as[i])
  87.       // 要给 5个链接绑定鼠标经过事件
  88.       as[i].addEventListener('mouseenter', function () {
  89.         // console.log('鼠标经过')
  90.         // 排他思想  
  91.         // 干掉别人 移除类active
  92.         document.querySelector('.tab-nav .active').classList.remove('active')
  93.         // 我登基 我添加类 active  this 当前的那个 a
  94.         this.classList.add('active')
  95.         // 下面5个大盒子 一一对应  .item
  96.         // 干掉别人
  97.         document.querySelector('.tab-content .active').classList.remove('active')
  98.         // 对应序号的那个 item 显示 添加 active 类
  99.         document.querySelector(`.tab-content .item:nth-child(${i + 1})`).classList.add('active')
  100.       })
  101.     }
  102.   </script>
  103. </body>
  104. </html>
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表