- UID
- 53330
- 帖子
- 117
- 精华
- 0
- 贡献
- 0
- 推广
- 0
- 有效BUG
- 0
- 注册时间
- 2007-4-3
|
- <script language="JavaScript">
- var strTopDomain = document.location.host;
- var txtRange;
- var strInput = window.prompt("请输入一个或多个关键字(用逗号分隔)\n空白则清除高亮", "");
- function Search_HighLight(doc)
- {
- var needScroll = true;
- var strDomain = doc.location.host;
- if (strInput)
- {
- var strKey = strInput.split(',');
- for (var i = 0; i < strKey.length; i++)
- {
- if (typeof(doc.body.createTextRange) == "object")
- {
- txtRange = doc.body.createTextRange();
- while (txtRange.findText(strKey[i]))
- {
- if (needScroll)
- {
- txtRange.scrollIntoView();
- needScroll = false;
- }
- txtRange.pasteHTML("<span id='search_highlight' style='background-color:yellow'>" + txtRange.text + "</span>");
- }
- }
- }
- }
- else
- {
- var txtRangeOld = doc.all["search_highlight"];
- if (txtRangeOld)
- if (txtRangeOld.length)
- for (var i = txtRangeOld.length - 1; i >= 0; i--)
- txtRangeOld[i].outerHTML = txtRangeOld[i].innerHTML;
- else
- txtRangeOld.outerHTML = txtRangeOld.innerHTML;
- }
- if ((strDomain == strTopDomain) && (doc.frames))
- {
- for (var i = 0; i < doc.frames.length; i++)
- {
- try
- {
- Search_HighLight(doc.frames[i].document);
- }
- catch (e) {}
- }
- }
- }
- Search_HighLight(document);
- </script>
- var strTopDomain = document.location.host;
- var txtRange;
- var strInput = window.prompt("请输入一个或多个关键字(用逗号分隔)\n空白则清除高亮", "");
- function Search_HighLight(doc)
- {
- var needScroll = true;
- var strDomain = doc.location.host;
- if (strInput)
- {
- var strKey = strInput.split(',');
- for (var i = 0; i = 0; i--)
- txtRangeOld[i].outerHTML = txtRangeOld[i].innerHTML;
- else
- txtRangeOld.outerHTML = txtRangeOld.innerHTML;
- }
- if ((strDomain == strTopDomain) && (doc.frames))
- {
- for (var i = 0; i < doc.frames.length; i++)
- {
- try
- {
- Search_HighLight(doc.frames[i].document);
- }
- catch (e) {}
- }
- }
- }
- Search_HighLight(document);
复制代码
以上是"页面内查找及高亮关键字"插件的代码. 会js的朋友能否帮忙改一下, 不要window.prompt("请输入一个或多个关键字...), 而是从搜索栏读取关键字....
谢谢 |
|