我已将时钟添加到 Pallab 的代码中。因此,即使在我的情况下为 10 秒的超时期限之前单击了不同的选项卡,当前选项卡将显示 10 秒,并且选项卡将在 5 秒后自动选项卡。我是初学者,所以请忍受我的编码。
您必须在不到 10 秒的时间内单击 2 个或更多选项卡,一次单击一个选项卡。
// Tab-Pane 改变函数
tabChange = function(){
var tabs = $('.nav-tabs > li');
var active = tabs.filter('.active');
var next = active.next('li').length? active.next('li').find('a') : tabs.filter(':first-child').find('a');
// Use the Bootsrap tab show method
next.tab('show');
} // Tab Cycle function
function settabchnge () {
//alert("in set tab");
tabCycle = setInterval(tabChange, 5000);
}
settabchnge();
function cleartabchange () {
clearInterval(tabCycle);
}
$(函数(){
var counterofclock = 1;
var counterofmoreclicks = 1;
var clicked = false;
var sec = 0;
function startClock() {
if (clicked === false) {
clock = setInterval(stopWatch, 1000);
clicked = true;
}else if (clicked === true) {
}
}
function stopWatch() {
sec++;
}
function stopClock() {
window.clearInterval(clock);
sec = 0;
clicked = false;
}
$('.nav-tabs a').click(function(e) {
if(counterofclock === 1){
startClock();
counterofclock = 2;
}else {
stopClock();
startClock();
}
e.preventDefault();
// Stop the cycle
if (counterofmoreclicks == 2 && sec < 11){
clearTimeout(starttabchnage);
}
counterofmoreclicks = 2;
clearInterval(tabCycle);
// Show the clicked tabs associated tab-pane
$(this).tab('show')
// Start the cycle again in a predefined amount of time
starttabchnage = setTimeout(function(){ settabchnge();}, 10000);
});
})