87,994
社区成员
发帖
与我相关
我的任务
分享
<style>
* {
margin: 0;
padding: 0;
}
ul,
li {
list-style: none;
}
ul {
overflow: hidden;
}
li {
float: left;
color: #f60;
padding: 20px 40px;
margin-right: 10px;
cursor: pointer;
border: 2px solid #f90;
transition: all ease .3s;
}
.box {
width: 550px;
margin: 10px auto;
position: relative
}
li:hover {
background: #f90;
color: #fff;
}
li.tabin {
background: #f90;
color: #fff
}
.content-box {
width: 550px;
height: 250px;
background: #f90;
position: absolute;
left: 0;
top: 63px;
overflow: hidden;
}
.content {
clear: both;
color: #fff;
padding: 10px;
opacity: 0;
transition: all ease .3s;
position: absolute;
top: 0;
left: 0;
}
.active {
opacity: 1;
}
.content h1 {
font-size: 18px;
margin-bottom: 20px;
margin-top: 20px;
}
.content p {
font-size: 14px;
}
button {
width: 100px;
height: 40px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<div class="box">
<ul id="tablist">
<li class="tabin">标签一</li>
<li>标签二</li>
<li>标签三</li>
</ul>
<div class="content-box">
<div class="content active">
<h1>标签一内容</h1>
<p>标签一</p>
<button class="btn" onclick="show(1)">按钮</button>
</div>
<div class="content">
<h1>标签二内容</h1>
<p>标签二</p>
<button class="btn" onclick="show(2)">按钮</button>
</div>
<div class="content">
<h1>标签三内容</h1>
<p>标签三</p>
<button class="btn" onclick="show(3)">按钮</button>
</div>
</div>
</div>
<script>
$(document).ready(function () {
$("#tablist li").each(function (index) {
$(this).click(function () {
$(".active").removeClass("active");
$(".tabin").removeClass("tabin");
$(".content-box div").eq(index).addClass("active");
$(this).addClass("tabin")
});
})
})
function show(v){
console.log('执行标签'+v+'按钮')
}
// 下面的代码复制到浏览器执行
var btn = document.querySelectorAll('.btn')
for (var i = 0; i < btn.length; i++){
(index => {
setTimeout(() => {
console.log('执行click当前时间(毫秒):'+Date.now())
btn[index].click()
// 默认800毫秒后执行,其后每次递增30毫秒
}, index * 30 + 800)
}
)(i)
}
</script>
let all = document.querySelectorAll(".qn-btn.ensure-btn");
for(let i = 0; i< all.length; i++){
all[i].click()
}