2009-11-24 4 views
0

var tabLinks = new Array(); var contentDivs = new Array();기본 탭 선택을 제거하고 scrollTo 효과를 추가하십시오.

함수 초기화() {

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

는 tabListItems에 scrollTo 방법을 추가하고도 (즉, 어떤 탭이 기본적으로 선택되지 않음) 기본 탭 선택을 제거하기 위해 찾고 있어요.

환호 벤 카트는

답변

0

는 할당은 탭 링크에 이벤트를 온 클릭 // 및 는 // = 0 첫 번째 탭 VAR 난을 강조;

(tabLink의 var id) { tabLinks [id] .onclick = showTab; tabLinks [id] .onfocus = function() {this.blur()}; if (i == 0) tabLinks [id] .className = ''; contentDivs [id] .className = 'tabContent hide'; i ++; } 굵게 표시된 부분이 수정되었습니다 .. !!

콘텐츠를 숨기고 기본 탭의 선택을 취소합니다 !!

누군가가 scrollList() 메소드를 tabListItems 부분에 추가하는 것을 도와야합니다 !!!