可以实现HTML页面的本页查询吗?好像CONTROL+F一样
可以实现HTML页面的本页查询吗?好像CONTROL+F一样
我想把搜索框做到页面上面
请指教!
问题点数:20、回复次数:5Top
1 楼slayerbb(名字被抢了)回复于 2005-06-29 17:02:36 得分 0
can but so complex..
Top
2 楼白夜花寒(远藤花已谢,白夜花未寒)回复于 2005-06-30 06:27:16 得分 0
instr vbs
js match用正则Top
3 楼lanyd(寻找甘当科学家的女人)回复于 2005-06-30 10:04:28 得分 0
需要吗?
你不会直接调用IE的ctrl+f啊...Top
4 楼MyGhosts(阿辉)回复于 2005-07-01 23:40:41 得分 10
全文搜索代码,仅供参考,代码转自本坛:
<script language="JavaScript">
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
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("没有找到。");
}
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("没有找到。");
}
}
return false;
}
</script>
<form name="search" onSubmit="return findInPage(this.string.value);">
<font size=3><input name="string" type="text" size=15 onChange="n = 0;"></font>
<input type="submit" value="搜索"> 查找页面关键字
</form>Top
5 楼yourlunch(健能)回复于 2005-07-02 17:57:47 得分 10
以前都遇过这问题,呵..帮你解决吧
---------------------------------------------------------------
<object id=saOC CLASSID=''clsid:B45FF030-4447-11D2-85DE-00C04FA35C89'' HEIGHT=0 width=0></object>
<input type=button value=搜索 onclick="saOC.NavigateToDefaultSearch()">
---------------------------------------------------------------
<script language="Javascript">
var NS4 = (document.layers); // Which browser?
var IE4 = (document.all);
var win = window; // window to search.
var n = 0;
function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
// Find next occurance of the given string on the page, wrap around to the
// start of the page if necessary.
if (NS4) {
// Look for match starting at the current point. If not found, rewind
// back to the first match.
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
// If not found in either direction, give message.
if (n == 0)
alert("Not found.");
}
if (IE4) {
txt = win.document.body.createTextRange();
// Find the nth match from the top of the page.
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
// If found, mark it and scroll it into view.
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
// Otherwise, start over at the top of the page and find first match.
else {
if (n > 0) {
n = 0;
findInPage(str);
}
// Not found anywhere, give message.
else
alert("Not found.");
}
}
return false;
}
</script>
<form name="search" onSubmit="return findInPage(this.string.value);">
<font size=3><input name="string" type="text" size=15 onChange="n = 0;"></font>
<input type="submit" value="查找">
</form>Top




