你在运行什么来像这样在本地 Intranet 上托管网页?
如果您使用某种服务器,如 Apache 或 IIS,则可以使用服务器端语言来创建搜索功能。在客户端使用纯 Javascript 创建搜索功能是不切实际的。
这是一个在 Apache 服务器上运行的 PHP 脚本可以做什么的示例https://stackoverflow.com/a/4090449/4422715 请记住,这是一段非常简单的代码,肯定会出现问题,但对于小规模使用,可能会值得做这样简单的事情。
编辑:OP 用 ASP 声明 IIS。
看了一圈,找到了http://www.codeproject.com/Articles/7296/Reading-Files-in-ASP-and-How-to-Search-for-a-parti
输入要搜索的单词的页面应该是这样的,比如说“search.htm”
<FORM METHOD=POST id=form1 action="searchresult.asp"
name=form1 onsubmit="return Check();">
Enter text to search for:
<INPUT TYPE=TEXT NAME=TextToSearch>
<P>
<INPUT TYPE=SUBMIT VALUE="Begin Search!" id=SUBMIT1 name=SUBMIT1>
</FORM>
那么“searchresult.asp”页面应该是:
'Search Text
Dim strtextToSearch
strtextToSearch = Request("TextToSearch")
'Now, we want to search all of the files
Dim fso
'Constant to read
Const ForReading = 1
Set fso = Server.CreateObject("Scripting.FileSystemObject")
'Specify the folder path to search.
Dim FolderToSearch
FolderToSearch = "D:\temp"
'Proceed if folder exists
if fso.FolderExists(FolderToSearch) then
Dim objFolder
Set objFolder = fso.GetFolder(FolderToSearch)
Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False
Dim FilesCounter
FilesCounter = 0 'Total files found
For Each objFile in objFolder.Files
Set objTextStream = fso.OpenTextFile(objFile.Path,ForReading)
'Read the content
strFileContents = objTextStream.ReadAll
If InStr(1,strFileContents,strtextToSearch,1) then
Response.Write objFile.Name & "<br>"
FilesCounter = FilesCounter + 1
End If
objTextStream.Close
Next
if FilesCounter = 0 then
Response.Write "Sorry, No matches found."
else
Response.Write "Total files found : " & FilesCounter
end if
'Destroy the objects
Set objTextStream = Nothing
Set objFolder = Nothing
else
Response.Write "Sorry, invalid folder name"
end if
Set fso = Nothing
以上是直接从链接网站复制粘贴。在运行之前查看链接的网站并通读代码!!!确保将“FolderToSearch”设置为您的根文档文件夹。
看起来这段代码只会直接查看您设置搜索的文件夹中的文件。如果您希望它读取子文件夹等,那么您需要弄清楚如何做到这一点对不起,我是不是 ASP 专家,您可以在网站的 ASP 部分发布此代码,并寻求有关此脚本目录递归的帮助。