var tabLinks = new Array(); var contentDivs = new Array();
function init(){
// Grab the tab links and content divs from the page
var tabListItems = document.getElementById('tabs').childNodes;
for ( var i = 0; i < tabListItems.length; i++ ) {
if ( tabListItems[i].nodeName == "LI" ) {
var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
var id = getHash( tabLink.getAttribute('href') );
tabLinks[id] = tabLink;
contentDivs[id] = document.getElementById( id );
}
}
// Assign onclick events to the tab links, and
// highlight the first tab
var i = 0;
for ( var id in tabLinks ) {
tabLinks[id].onclick = showTab;
tabLinks[id].onfocus = function() { this.blur() };
if ( i == 0 ) tabLinks[id].className = 'selected';
i++;
}
// Hide all content divs except the first
var i = 0;
for ( var id in contentDivs ) {
if ( i != 0 ) contentDivs[id].className = 'tabContent hide';
i++;
}
}
function showTab(){ var selectedId = getHash(this.getAttribute('href'));
// Highlight the selected tab, and dim all others.
// Also show the selected content div, and hide all others.
for ( var id in contentDivs ) {
if ( id == selectedId ) {
tabLinks[id].className = 'selected';
contentDivs[id].className = 'tabContent ';
} else {
tabLinks[id].className = '';
contentDivs[id].className = 'tabContent hide';
}
}
// Stop the browser following the link
return false;
}
在上面的javascript中,我希望将scrollTo方法添加到tabListItems并删除默认选项卡选项(即默认情况下未选中任何选项卡)。
欢呼声 venkat
答案 0 :(得分:0)
//将onclick事件分配给选项卡链接,以及 //突出显示第一个标签 var i = 0;
for(tabLinks中的var id){ tabLinks [id] .onclick = showTab; tabLinks [id] .onfocus = function(){this.blur()}; if(i == 0)tabLinks [id] .className =''; contentDivs [id] .className ='tabContent hide'; 我++; 强> } 粗体部分已被调整.. !!
使隐藏内容并取消选择默认选项卡!!
有人应该帮我将scrollTo()方法添加到tabListItems部分!!!