网页上的按钮可以实现"查找"功能么?

如果能,怎样写代码阿?
---------------------------------------------------------------

object id=saOC CLASSID='clsid:B45FF030-4447-11D2-85DE-00C04FA35C89' HEIGHT=0 width=0>

1<input onclick="saOC.NavigateToDefaultSearch()" type="button" value="搜索"/>

---------------------------------------------------------------

 1<script language="JavaScript">   
 2var NS4 = (document.layers); // Which browser?   
 3var IE4 = (document.all);   
 4var win = window; // window to search.   
 5var n = 0;   
 6function findInPage(str) {   
 7var txt, i, found;   
 8if (str == "")   
 9return false;   
10// Find next occurance of the given string on the page, wrap around to the   
11// start of the page if necessary.   
12if (NS4) {   
13// Look for match starting at the current point. If not found, rewind   
14// back to the first match.   
15if (!win.find(str))   
16while(win.find(str, false, true))   
17n++;   
18else   
19n++;   
20// If not found in either direction, give message.   
21if (n == 0)   
22alert("Not found.");   
23}   
24if (IE4) {   
25txt = win.document.body.createTextRange();   
26// Find the nth match from the top of the page.   
27for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {   
28txt.moveStart("character", 1);   
29txt.moveEnd("textedit");   
30}   
31// If found, mark it and scroll it into view.   
32if (found) {   
33txt.moveStart("character", -1);   
34txt.findText(str);   
35txt.select();   
36txt.scrollIntoView();   
37n++;   
38}   
39// Otherwise, start over at the top of the page and find first match.   
40else {   
41if (n > 0) {   
42n = 0;   
43findInPage(str);   
44}   
45// Not found anywhere, give message.   
46else   
47alert("Not found.");   
48}   
49}   
50return false;   
51}   
52</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