ericleesky
|
分享:
x0
|
[JScript][讨论] 网页文字搜寻引擎
‧步骤一:将以下原始码加入<HEAD>与</HEAD>标签之间.
<!-- var NS4 = (document.layers); var IE4 = (document.all); var win = this; var n = 0; function findInPage(str) { var txt, i, found; if (str == "") return false; if (NS4) { if (!win.find(str)) while(win.find(str, false, true)) n++; else n++; if (n == 0) alert("此网页无法找到关键字" + str ); } 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("此网页无法找到关键字" + str ) }} return false; } // --> </script>
‧步骤二:将以下原始码加入网页中欲出现搜寻引擎之位置即可.
<form name=search> <font color="#CC0000">请输入你想寻找的关键字,仅限本网页</font><BR> <input name=string type=text size=15 onfiltered="n = 0;"> <input type=button value="搜寻" onfiltered="findInPage(this.form.string.value);"></form>
|