Bootstrap 如何在页面加载时设置默认导航栏标签

3b6akqbq  于 2023-09-28  发布在  Bootstrap
关注(0)|答案(1)|浏览(230)

我试图设置默认导航栏标签时,网页加载。我试图设置默认导航栏标签是'卖我的车'这个标签是打开时,页面加载。我该怎么做有导航栏选项卡。

function Default() {
    var tab= document.getElementsByClassName('defaulttab');
    window.onload(tab).click();
}
<a class="nav-link tablink active" id="v-pills-home-tab" data-toggle="pill" href="#my-adverts" role="tab" aria-controls="v-pills-home" aria-selected="true">My Adverts</a>
<a class="nav-link tablink defaulttab" id="v-pills-profile-tab "  data-toggle="pill" href="#sell-your-car" role="tab" aria-controls="v-pills-profile" aria-selected="false">Sell my car</a>
<a class="nav-link tablink" id="v-pills-messages-tab" data-toggle="pill" href="#change-package" role="tab" aria-controls="v-pills-messages" aria-selected="false">Change Package</a>
5vf7fwbs

5vf7fwbs1#

只需在默认导航链接上设置active class,不需要额外的js:

<a class="nav-link tablink" id="v-pills-home-tab" data-toggle="pill" href="#my-adverts" role="tab" aria-controls="v-pills-home" aria-selected="false">My Adverts</a>
<a class="nav-link tablink active" id="v-pills-profile-tab "  data-toggle="pill" href="#sell-your-car" role="tab" aria-controls="v-pills-profile" aria-selected="true">Sell my car</a>
<a class="nav-link tablink" id="v-pills-messages-tab" data-toggle="pill" href="#change-package" role="tab" aria-controls="v-pills-messages" aria-selected="false">Change Package</a>

相关问题