设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > ASP

Asp初学者常见问题之八怎么让搜索出来的关键字变红色

作者:佚名 出处:网络转载 时间:07-22 点击:

内容载入中...
Function Highlight(strText, strFind, strBefore, strAfter)
Dim nPos
Dim nLen
Dim nLenAll

nLen = Len(strFind)
nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1

Highlight = strText

If nLen > 0 And Len(Highlight) > 0 Then
nPos = InStr(1, Highlight, strFind, 1)
Do While nPos > 0
Highlight = Left(Highlight, nPos - 1) & _
strBefore & Mid(Highlight, nPos, nLen) & strAfter & _
Mid(Highlight, nPos + nLen)

nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
Loop
End If
End Function


使用:

Response.Write Highlight(myText, "someword", "<font color=red>", "</font>")
收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息