• λ我爱Aspx >> Asp.Net >> 在ASP应用程序中加入智能搜索
  • 在ASP应用程序中加入智能搜索

  • :aspxer  Դ:internet  :2007-5-15 20:47:28  ؼ:asp
  • <%

    Else

    %>

    搜索名称为“<font color="#FF0000"><%= S_Key %></font>”的项,共找到 <font color="#FF0000"><%= RST.RecordCount %></font> 项:<p>

    <%

    While Not RST.EOF 遍历整个记录集,显示搜索到的信息并设置链接

    %>

    <!-- 此处可设为你所需要的链接目标 -->

    <font style="font: 12pt 宋体"><a href="info.asp?ID=<%= RST("ID") %>" target="_blank"><%= RST("U_Name") %></a></font>

    <!-- 显示部分详细内容 -->

    <font style="font: 9pt 宋体"><%= Left(RST("U_Info"),150) %></font><p>

    <%

    RST.MoveNext

    Wend

    RST.Close

    Set RST=Nothing

    End If

    End If

    %>

    在上面的代码中,有一个自定义函数 AutoKey ,该函数是实现智能搜索的核心所在。代码如下:

    <%

    Function AutoKey(strKey)

    CONST lngSubKey=2

    Dim lngLenKey, strNew1, strNew2, i, strSubKey

    检测字符串的合法性,若不合法则转到出错页。出错页你可以根据需要进行设定。

    if InStr(strKey,"=")<>0 or InStr(strKey,"`")<>0 or InStr(strKey,"")<>0 or InStr(strKey," ")<>0 or InStr(strKey," ")<>0 or InStr(strKey,"")<>0 or InStr(strKey,chr(34))<>0 or InStr(strKey,"\")<>0 or InStr(strKey,",")<>0 or InStr(strKey,"<")<>0 or InStr(strKey,">")<>0 then

    Response.Redirect "error.htm"

    End If

    lngLenKey=Len(strKey)

    Select Case lngLenKey

    Case 0 若为空串,转到出错页

    Response.Redirect "error.htm"

    Case 1 若长度为1,则不设任何值

    strNew1=""

    strNew2=""

    Case Else 若长度大于1,则从字符串首字符开始,循环取长度为2的子字符串作为查询条件

    For i=1 To lngLenKey-(lngSubKey-1)

    Ҷƪл˵?
  • һƪ如何利用ASP实现邮箱访问
    һƪ在ASP应用程序中限制重复提交同一表单