[英]Random 'active' nav-tab (Bootstrap)
How can I make my Bootstrap 'nav-tabs' tab be dynamic and randomize the active one on document load (everytime site loads)?如何使我的 Bootstrap 'nav-tabs' 标签成为动态的并在文档加载时随机化活动标签(每次网站加载)?
I have the following schema: https://www.bootply.com/scKyFxqsNG我有以下架构: https : //www.bootply.com/scKyFxqsNG
Thanks谢谢
You can do something like this:你可以这样做:
$(document).ready(function(){
//Generate random number
var rand = Math.floor(Math.random()*3);
//Select `li` at random and add a class
$("#home-tabs-menu li").eq(rand).addClass('active');
// Select `li a` at random and use .show();
$("#home-tabs-menu li a").eq(rand).show();
});
On every load, use javascript random to get a number and set the active class depending on the result在每次加载时,使用 javascript random 获取一个数字并根据结果设置活动类
var i = Math.floor(Math.random() * 3) + 1
if(i == 1)
$("#tab1").addClass(".active")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.