静态页面全文检索功能如何实现?

 1<script language="JavaScript">   
 2var NS4 = (document.layers);   
 3var IE4 = (document.all);   
 4var win = window;   
 5var n = 0;   
 6function findInPage(str) {   
 7var txt, i, found;   
 8if (str == "")   
 9return false;   
10if (NS4) {   
11if (!win.find(str))   
12while(win.find(str, false, true))   
13n++;   
14else   
15n++;   
16if (n == 0)   
17alert("没有找到。");   
18}   
19if (IE4) {   
20txt = win.document.body.createTextRange();   
21for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {   
22txt.moveStart("character", 1);   
23txt.moveEnd("textedit");   
24}   
25if (found) {   
26txt.moveStart("character", -1);   
27txt.findText(str);   
28txt.select();   
29txt.scrollIntoView();   
30n++;   
31}   
32else {   
33if (n > 0) {   
34n = 0;   
35findInPage(str);   
36}   
37else   
38alert("没有找到。");   
39}   
40}   
41return false;   
42}   
43</script>
1<form name="search" onsubmit="return findInPage(this.string.value);">
2<font size="3"><input name="string" onchange="n = 0;" size="15" type="text"/></font>
3<input type="submit" value="搜索"/> 查找页面关键字   
4</form>
Published At
Categories with Web编程
comments powered by Disqus