0

var tabLinks = new Array(); var contentDivs = new Array();

函数初始化(){

   // 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++;
   }
 }

函数 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 并删除默认选项卡选择(即,默认情况下不选择选项卡)。

干杯文卡特

4

1 回答 1

0

// 将 onclick 事件分配给选项卡链接,并 // 突出显示第一个选项卡 var i = 0;

for ( var id in tabLinks ) { tabLinks[id].onclick = showTab; tabLinks[id].onfocus = function() { this.blur() }; if ( i == 0 ) tabLinks[id].className = ''; contentDivs[id].className = 'tabContent hide'; 我++; } 粗体部分已被调整..!!

这使得隐藏内容并取消选择默认选项卡!

有人应该帮我将 scrollTo() 方法添加到 tabListItems 部分!!!

于 2009-11-24T23:27:21.140 回答