手机端如何实现类似于电脑端的ctrl+f功能?下面代码在手机端测试只能让搜索文字改变颜色,没办法自动跳到搜索结果哪里,哪位大神大神知道目前想在手机端实现ctrl+f功能用什么方式最好。
var win = window;
var n   = 0;
function findIt() {
    if (document.getElementById("searchstr").value != "")
        findInPage(document.getElementById("searchstr").value);
}
function findInPage(str) {
var txt, i, found;
if (str == "")
    return false;
if (DOM)
{
    win.find(str, false, true);
    return true;
}
if (NS4) {
    if (!win.find(str))
        while(win.find(str, false, true))
            n++;
    else
        n++;
    if (n == 0)
        alert("娌℃湁鎵惧埌杩欎釜鍦板潃锛岃纭畾浼氶噸鏂版悳绱�.");
}
if (IE4) {
    txt = win.document.body.createTextRange();
    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
        txt.moveStart("character", 1);
        txt.moveEnd("textedit");
    }
if (found) {
    txt.moveStart("character", -1);
    txt.findText(str);
    txt.select();
    txt.scrollIntoView();
    n++;
}
else {
    if (n > 0) {
        n = 0;
        findInPage(str);
    }
    else
        alert("娌℃湁鎵惧埌杩欎釜鍦板潃锛岃纭畾浼氶噸鏂版悳绱�.");
    }
}
return false;
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
让浏览器自己实现比较好。
不要多事。