你在運行什麼來在本地內網上託管網頁?
如果您使用某種類型的服務器,如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部分發布這些代碼,也可以通過此腳本幫助用戶獲得目錄遞歸的幫助。
該網站在IIS上。我對網絡編程很陌生,因此我對Html/CSS/Javascript/php/etc沒有任何經驗。你能指出我的代碼,這將符合我的需要在IIS而不是Apache?謝謝 – dushkin
當然,我會給它一個並更新上面的答案:) – Aaron
非常感謝你 – dushkin