我已经成功实现了UIWebView搜索文本,现在我想浏览下一次出现的所有内容和之前的内容,任何人都可以在UIWebView中进行推荐。非常感谢。
非常感谢
答案 0 :(得分: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} }