gpt4 book ai didi

javascript - 单击jquery,在页面加载时添加类

转载 作者:行者123 更新时间:2023-11-28 07:38:01 25 4
gpt4 key购买 nike

已解决

1st 这是为另一个问题创建的,但由于我的一些草率举动我解决了它......无论如何我遇到了另一个问题,那就是在 li 上添加类 current code>,带有 data-tab="tab-1,在页面加载时。

$('ul.tabs li').click(function(){
var tab_id = $(this).attr('data-tab');

$('ul.tabs li').removeClass('current');
$('.tab-content').removeClass('current');

$(this).addClass('current');
$("#"+tab_id).addClass('current');
});
.tabs li.current {
color: red;
}
.tab-content {
display: none;
}
.tab-content.current {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="innovation">
<div class="categories-wrap">
<ul class="tabs">
<li class="tab-link" data-tab="tab-1">
<i class="sprite-call-black"></i>
<h4>Pristine coverage</h4>
<p>Enjoy your calls without interuptions like dropped calls, poor sound quality, and delayed video.</p>
</li>
<li class="tab-link" data-tab="tab-2">
<i class="sprite-call-black"></i>
<h4>Chat messaging</h4>
<p>Chat in real time with connections all around the world. </p>
</li>
<li class="tab-link" data-tab="tab-3">
<i class="sprite-call-black"></i>
<h4>Video calling</h4>
<p>WiFi paired with reliable cellular service is how we’ve got you covered in more places than ever before.</p>
</li>
<li class="tab-link" data-tab="tab-4">
<i class="sprite-call-black"></i>
<h4>Photo share</h4>
<p>WiFi paired with reliable cellular service is how we’ve got you covered in more places than ever before.</p>
</li>
</ul>
</div>
<div class="tabs-wrap">
<div id="tab-1" class="tab-content current">
<img src="" alt="Pristine Coverage">
</div>
<div id="tab-2" class="tab-content">
<img src="" alt="Chat Messaging">
</div>
<div id="tab-3" class="tab-content">
<img src="" alt="Video Calling">
</div>
<div id="tab-4" class="tab-content">
<img src="" alt="Photo Share">
</div>
</div>
</section>

最佳答案

用这个?

$(document).ready(function () {
$(".current").removeClass("current");
$(".tabs-wrap #tab-1").addClass("current");
});

关于javascript - 单击jquery,在页面加载时添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31123748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com