2012-12-14 75 views

回答

1

我可以使用來實現這一結果javascript函數

function goNext(){ 
    jump(1); 
} 
function goPrev(){ 
    jump(-1); 
} 

function jump(nextOrPrev){ 


    prevSelected = currSelected; 
    currSelected = currSelected + nextOrPrev; 

    if (currSelected < 0){ 
     currSelected = uiWebview_SearchResultCount + currSelected; 
    } 
    if (currSelected >= uiWebview_SearchResultCount){ 
     currSelected = currSelected - uiWebview_SearchResultCount; 
    } 

    prevEl = document.getElementsByClassName("uiWebviewHighlight")[prevSelected]; 
    if (prevEl){ 
     prevEl.style.backgroundColor="yellow"; 
    } 
    el = document.getElementsByClassName("uiWebviewHighlight")[currSelected]; 
    el.style.backgroundColor="green"; 
    el.scrollIntoView(true); 
} 

不要初始化currSelected = -1元素的比較之前,你的搜索功能的開始,這應該是像這樣

if (element) { 
     if (element.nodeType == 3) { //your code} } 
相關問題