【闪星提问】怎样在查询结果中对查询的关键字用不同的颜色显示出来~~谢谢

shanxing 2004-04-22 03:23:16
【闪星提问】怎样在查询结果中对查询的关键字用不同的颜色显示出来~~谢谢
...全文
84 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lawdoor 2004-04-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>")
shanxing 2004-04-22
  • 打赏
  • 举报
回复
谢谢
晚上回去试试了
liuyu202 2004-04-22
  • 打赏
  • 举报
回复
楼上的可以!
ttt2 2004-04-22
  • 打赏
  • 举报
回复
set rs=server.createobject("adodb.recordset")
rs.open "select * from temp where title like '%"&gjz&"%'",cn,1,3
while not rs.eof
%>
<%=replace(title,gjz,"<font color=red>"&gjz&"</font>")%>
<%
rs.movenext
wend
ydh1981 2004-04-22
  • 打赏
  • 举报
回复
<%=replace(rs("t_description"),100),keyWord,"<font color=#ff0000>"&keyWord&"</font>")%>
xuanhu 2004-04-22
  • 打赏
  • 举报
回复
显示时加上<font color=red>关键字</font>不就可以了?
得到查询的关键字后,
title=replace(数据名,"关键字","<font color=red>关键字</font>")
response.write title
shanxing 2004-04-22
  • 打赏
  • 举报
回复
to ttt2(家合万事兴)
能否给个例子参考一下
angelheavens 2004-04-22
  • 打赏
  • 举报
回复
处理方式有很多

假设查询关键字KeyWord为:"显示"
结果有N条
那么输出时: Response.Write(Replace(Content,KeyWord,"<font color=red>"&KeyWord&"</font>")
ttt2 2004-04-22
  • 打赏
  • 举报
回复
replace(str,"结果","<font color=red>结果</font>")

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧