标签:播放 ack splay mda width name 判断 nbsp button
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div class="mydiv1"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> </body> <script> // 第一个需求 一个选项卡; let btns = document.querySelectorAll(".mydiv1 button"); let ps = document.querySelectorAll(".mydiv1 p"); btns.forEach((v,k)=>{ v.onclick = function(){ ps.forEach((value,key)=>{ if(key==k){ // 选中项; btns[key].style.background = "red"; ps[key].style.display = "block"; }else{ // 非选中项; btns[key].style.background = ""; ps[key].style.display = "none"; } }) } }) </script> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div class="mydiv1"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> <div class="mydiv2"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> </body> <script> // 第二个需求 多个选项卡; function Tab(btns, ps) { btns.forEach((v, k) => { v.onclick = function () { ps.forEach((value, key) => { if (key == k) { // 选中项; btns[key].style.background = "red"; ps[key].style.display = "block"; } else { // 非选中项; btns[key].style.background = ""; ps[key].style.display = "none"; } }) } }) } let btns = document.querySelectorAll(".mydiv1 button"); let ps = document.querySelectorAll(".mydiv1 p"); Tab(btns,ps); let btns2 = document.querySelectorAll(".mydiv2 button"); let ps2 = document.querySelectorAll(".mydiv2 p"); Tab(btns2,ps2); </script> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div class="mydiv1"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> <div class="mydiv2"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> <button class="nextPre">点击我第一个选项卡下一页切换</button> </body> <script> // 第三个需求 3-点击按钮第一个选项卡有下一页功能 function Tab(btns, ps, isNext = false) { btns.forEach((v, k) => { v.onclick = function () { psFor(k); } }) if (isNext) { // 有下一页功能; let num = 0; document.querySelector(".nextPre").onclick = function () { num++; num = num > 2 ? 0 : num psFor(num); } } function psFor(k) { ps.forEach((value, key) => { if (key == k) { // 选中项; btns[key].style.background = "red"; ps[key].style.display = "block"; } else { // 非选中项; btns[key].style.background = ""; ps[key].style.display = "none"; } }) } } let btns = document.querySelectorAll(".mydiv1 button"); let ps = document.querySelectorAll(".mydiv1 p"); Tab(btns, ps, true); let btns2 = document.querySelectorAll(".mydiv2 button"); let ps2 = document.querySelectorAll(".mydiv2 p"); Tab(btns2, ps2); </script> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div class="mydiv1"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> <div class="mydiv2"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> <button class="nextPre">点击我第一个选项卡下一页切换</button> <button class="autoPlay">点击按钮第二个选项卡有自动轮播功能</button> </body> <script> // 第四个需求 4-点击按钮第二个选项卡有自动轮播功能 function Tab(btns, ps, isNext = false, isAutoPlay = false) { btns.forEach((v, k) => { v.onclick = function () { psFor(k); } }) if (isNext) { // 有下一页功能; let num = 0; document.querySelector(".nextPre").onclick = function () { num++; num = num > 2 ? 0 : num psFor(num); } } if (isAutoPlay) { // 控制自动轮播 let num = 0; document.querySelector(".autoPlay").onclick = function () { setInterval(() => { num++; num = num > 2 ? 0 : num psFor(num); }, 1000); } } function psFor(k) { ps.forEach((value, key) => { if (key == k) { // 选中项; btns[key].style.background = "red"; ps[key].style.display = "block"; } else { // 非选中项; btns[key].style.background = ""; ps[key].style.display = "none"; } }) } } let btns = document.querySelectorAll(".mydiv1 button"); let ps = document.querySelectorAll(".mydiv1 p"); // 下一页功能 轮播功能; 某一个选项卡的需求; Tab(btns, ps, true); let btns2 = document.querySelectorAll(".mydiv2 button"); let ps2 = document.querySelectorAll(".mydiv2 p"); Tab(btns2, ps2, false, true); </script> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div class="mydiv1"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> <div class="mydiv2"> <button style="background: red">按钮一</button> <button>按钮二</button> <button>按钮三</button> <p style="display: block;">div1</p> <p style="display: none;">div2</p> <p style="display: none;">div3</p> </div> <button class="nextPre">点击我第一个选项卡下一页切换</button> <button class="autoPlay">点击按钮第二个选项卡有自动轮播功能</button> </body> <script> // 第四个需求 4-点击按钮第二个选项卡有自动轮播功能 function Tab(btns, ps) { btns.forEach((v, k) => { v.onclick = function () { psFor(k); } }) // if (isNext) { // // 有下一页功能; // let num = 0; // document.querySelector(".nextPre").onclick = function () { // num++; // num = num > 2 ? 0 : num // psFor(num); // } // } // if (isAutoPlay) { // // 控制自动轮播 // let num = 0; // document.querySelector(".autoPlay").onclick = function () { // setInterval(() => { // num++; // num = num > 2 ? 0 : num // psFor(num); // }, 1000); // } // } function psFor(k) { ps.forEach((value, key) => { if (key == k) { // 选中项; btns[key].style.background = "red"; ps[key].style.display = "block"; } else { // 非选中项; btns[key].style.background = ""; ps[key].style.display = "none"; } }) } return psFor; } let btns = document.querySelectorAll(".mydiv1 button"); let ps = document.querySelectorAll(".mydiv1 p"); // 下一页功能 轮播功能; 一个需求; let tab1 = Tab(btns, ps); // 下一页功能 let num = 0; document.querySelector(".nextPre").onclick = function () { num++; num = num > 2 ? 0 : num tab1(num); } let btns2 = document.querySelectorAll(".mydiv2 button"); let ps2 = document.querySelectorAll(".mydiv2 p"); let tab2 = Tab(btns2, ps2); // 自动轮播 let num2 = 0; document.querySelector(".autoPlay").onclick = function () { setInterval(() => { num2++; num2 = num2 > 2 ? 0 : num2 tab2(num2); }, 1000); } </script> </html>
标签:播放 ack splay mda width name 判断 nbsp button
原文地址:https://www.cnblogs.com/supermanGuo/p/11395890.html