写的匆忙,示意一下,有待完善。把以下代码复制到文本文件中,把文件扩展名改为.html就可以运行了。

<html>
<head>
<style type="text/css">
.res
{
color: Red;
}
</style>
<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var oldKey = "";
var index = -1;
var pos = new Array();
var oldCount = 0; function search(flg) {
if (!flg) {
index++;
index = index == oldCount ? 0 : index;
}
else {
index--;
index = index < 0 ? oldCount - 1 : index;
} $(".result").removeClass("res");
$("#toresult").remove();
var key = $("#key").val(); //取key值
if (!key) {
oldKey = "";
return; //key为空则退出
} if (oldKey != key) {
//重置
index = 0;
$(".result").each(function () {
$(this).replaceWith($(this).html());
});
pos = new Array(); $("body").html($("body").html().replace(new RegExp(key, "gm"), "<span id='result" + index + "' class='result'>" + key + "</span>")); // 替换 $("#key").val(key);
oldKey = key;
$(".result").each(function () {
pos.push($(this).offset().top);
});
oldCount = $(".result").length;
} $(".result:eq(" + index + ")").addClass("res"); $("body").scrollTop(pos[index]);
}
</script>
</head>
<body>
<div style="position: fixed; right: 20px; top: 0;">
<input id="key" type="text" style="width: 100px;" />
<input type="button" value="下一个" onclick="search()" />
<input type="button" value="上一个" onclick="search(1)" />
</div>
<div style="height: 50px;">
</div>
<div style="height: 200px;">
1待搜索的文本。
</div>
<div style="height: 200px;">
2待搜索的文本。
</div>
<div style="height: 200px;">
3待搜索的文本。
</div>
<div style="height: 200px;">
4待搜索的文本。
</div>
<div style="height: 200px;">
5待搜索的文本。
</div>
<div style="height: 200px;">
10美丽的家乡。
</div>
<div style="height: 200px;">
11美丽的家乡。
</div>
<div style="height: 200px;">
12美丽的家乡。
</div>
<div style="height: 200px;">
13美丽的家乡。
</div>
<div style="height: 200px;">
14美丽的家乡。
</div>
<div style="height: 200px;">
15美丽的家乡。
</div>
</body>
</html>

模拟浏览器搜索功能(Ctrl + F)的更多相关文章

  1. 前端页面模拟浏览器搜索功能Ctrl+F实现

    <html> <head> <style type="text/css"> .res { color: Red; } .result{ back ...

  2. 利用api模拟百度搜索功能

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. UltraEdit (Ctrl + F) 查找、(Ctrl + R)替换功能失效

    环境: Windows 7 Service Pack 1 X64 工具: UltraEdit Version 21 症状: UltraEdit (Ctrl + F) 查找.(Ctrl + R)替换功能 ...

  4. idea 模糊搜索 ctrl + f(单词不完整搜索不到的解决办法)

    1,现象描述,笔者在用 idea 的 ctrl + f 搜索文件的内容时,发现了很神奇的问题,就是字符串必须输入完整才能搜索到,输入一半,哪怕是个字母输入了9个也搜不到 2,可以发现,就差一个字母 h ...

  5. 原生javascript实现 下拉框搜索功能

    由于业务需求,要实现 一个下拉框搜索功能.这个下拉功能和百度的还是有点区别的,百度的是时时与服务器交互的,而这个只是模拟.技术点在于实现 了搜索功能. 未搜索前如下图: 搜索后: <!DOCTY ...

  6. python--selenium简单模拟百度搜索点击器

    python--selenium简单模拟百度搜索点击器 发布时间:2018-02-28 来源:网络 上传者:用户 关键字: selenium 模拟 简单 点击 搜索 百度 发表文章摘要:用途:简单模拟 ...

  7. idea 光标变成粗体且当前文件搜索功能无法使用的问题

    今天安装了idea最新版,安装完成后发现光标变成了粗体,并且快捷键在使用时出现了问题,比如:ctrl+F搜索功能无法使用 经过反复修改配置也无法改善情况,后来一次重启看到下面小窗弹出有关vim的一个提 ...

  8. Python使用mechanize模拟浏览器

    Python使用mechanize模拟浏览器 之前我使用自带的urllib2模拟浏览器去进行訪问网页等操作,非常多站点都会出错误,还会返回乱码.之后使用了 mechanize模拟浏览器,这些情况都没出 ...

  9. java模拟浏览器包selenium整合了htmlunit,火狐浏览器,IE浏览器,opare浏览器驱

    //如果网页源码中有些内容是js渲染过来的,那你通过HttpClient直接取肯定取不到,但是这些数据一般都是通过异步请求传过来的(一般都是通过ajax的get或者post方式).那么你可以通过火狐浏 ...

随机推荐

  1. SSTable and Log Structured Storage: LevelDB

    If Protocol Buffers is the lingua franca of individual data record at Google, then the Sorted String ...

  2. [原创]android自定义动画的一点感悟

    android提供了一系列的动画处理api,包括animator以及animation等.由于动画效果是根据人眼视觉残留原理形成的,因此动画过程中android需要不断频繁的更新view的相关属性,由 ...

  3. file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did

    file_get_contents()获取https出现这个错误Unable to find the wrapper “https” – did 解决办法 ,如果你是用的服务器,可以参考这个办法,修改 ...

  4. PowerShell读取Windows产品密钥

    之前大多数人可能用过VBS读取Windows产品密钥的VBS脚本,VBS脚本通常都比较隐晦.难懂,今天忙里偷闲,随手写了一个用于读取Windows产品密钥的PowerShell脚本. 代码如下: == ...

  5. windbg常用命令

    SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols CPU常用命令 载入sos.dll  执行.load C:\Windows\Micr ...

  6. mac安装 配置 ant

    转自:http://blog.sina.com.cn/s/blog_877e9c3c0101qs87.html 1.下载ant 官网下载 http://ant.apache.org/bindownlo ...

  7. Onmouseover被调用多次

    当一个容器,如div,不包含元素时.Onmouseover只执行一次,正常.当这个div包含其他子元素的时候,这个事件就被执行了多次,今天遇到了这个问题,特此记录下,解决方案. 这个是由于onmous ...

  8. sqlserver 字符串最后一次的位置,截取字符串

    --reverse:字符串倒排 SUBSTRING(字段,1,len(字段)- CHARINDEX('-',REVERSE(字段)))

  9. How to Debug Enterprise Portal Code in Dynamics AX 2009

    转载 To set up debugging for pages1. Log into the server that is running the AOS.2. Open the Microsoft ...

  10. FFmpeg编译出错_img_convert 找不到

    问题出现在下载的ffmpeg的版本不一样,在0.4.8以前的版本中还有img_convert这个函数,新版本中用sws_getContext和sws_scale代替了.简单说明如下: 新版本的ffmp ...