如何给html文件做搜索
来源:百度知道 编辑:UC知道 时间:2024/05/22 01:08:01
因为是直接安装在用户的机器上,所以不可能使用数据库等方法。(同时也不需要编译成chm格式的文件)。只能通过原始的搜索代码实现站内搜索。请问应该如何实现搜索主题的功能。
虽然没分,还是把我从别处抄来的代码转给你吧:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test</title>
</head>
<body style="font-size: 10pt">
<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++; <