ASP网站搜索关键字高亮显示代码

我想在网站的搜索结果页面加入高亮关键字功能,在网上找了很多段代,不知道怎么用,把我的搜索页面的代码贴出来,麻烦帮我改一下,万分感谢!<!--#includefile=co... 我想在网站的搜索结果页面加入高亮关键字功能,在网上找了很多段代,不知道怎么用,把我的搜索页面的代码贴出来,麻烦帮我改一下,万分感谢!

<!--#include file=common/conn.asp-->

<link href="common/style.css" rel="stylesheet" type="text/css">
<body>
<!--#include file=common/head.asp-->
<%dim m,n,keyword,searchsl
keyword=request("keyword")
searchsl=request("searchsl")

if searchsl = "1" then
exec="select * from info where topic like '%"&keyword&"%' and state = 1 order by id Desc"
else
exec="select * from info where content like '%"&keyword&"%' and state = 1 order by id Desc"
end if
'----------------------------------------------------------------------------------------------------
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
rs.pagesize=40
tatalrecord=rs.recordcount
tatalpages=rs.pagecount

%>

<table width="960" align="center">
<tr>
<td colspan="4">

</td>
</tr>
<tr>
<td height="50" colspan="4" bgcolor="#F2F2F2" class="border">
<!--#include file=common/search.asp-->
</td>
</tr>
<tr>
<td colspan="4">

</td>
</tr>
<tr>
<td class="border" valign="top" width="210">
<!--#include file=left.asp-->

</td>
<td width="4">

</td>
<td width="710" valign="top" class="border">

<table class="text3" width="700">
<tr>
<td colspan="4">
关键字"<strong><font color="#006633">
<% response.Write keyword %>
</font></strong>" 共有 <%=tatalrecord%> 条搜索结果: </td>
</tr>
<tr>
<td colspan="4" background="images/line.gif"><td width="7">
</tr>

<%

if rs.eof and rs.bof then
response.Write ("<tr><td><font size=2>对不起,没有相匹配的内容!</font></td></tr>")
else
rs.movefirst
nowpage=request("page")
if nowpage&"x"="x"then
nowpage=1
else
nowpage=cint(nowpage)
end if
rs.absolutepage=nowpage
n=1
%>
<% n=1
while not rs.eof and n<=rs.pagesize
%>

'只有这里的topic和content需要高亮关键字显示----

<tr>
<td colspan="4">[<%=rs("createtime")%>] <font color="#006633"><%=rs("topic")%></font></td>
</tr>
<tr>
<td colspan="4"><%=rs("content")%></td>
'----------------------------------------------------------------
展开
 我来答
百度网友a14540ab0
2006-11-22 · TA获得超过240个赞
知道小有建树答主
回答量:454
采纳率:0%
帮助的人:346万
展开全部
你的代码的最后4行行换成这样
<%ttopic=replace(rs("topic"),keyword,"<font color=red>"&keyword&"</font>")
ccontent=replace(rs("content"),keyword,"<font color=red>"&keyword&"</font>")
%>
<td colspan="4">[<%=rs("createtime")%>] <font color="#006633"><%response.write ttopic%></font></td>
</tr>
<tr>
<td colspan="4"><%response.write ccontent%></td>

<%>
OruA
2006-11-22 · 超过54用户采纳过TA的回答
知道小有建树答主
回答量:115
采纳率:0%
帮助的人:161万
展开全部
<font color="#006633"><%=rs("topic")%></font></td>
</tr>
<tr>
<td colspan="4"><%=rs("content")%></td>
---------------------改
先定义个css
.highlight{
color:#FF0000;
background-color:FFFF00;
}
<%dim topic,content,
topic=replace(rs("topic"),keyword,"<SPAN CLASS=HIGHTLIGHT>"&keyword&"</SPAN>")
content=replace(rs("content"),keyword,"<SPAN CLASS=HIGHTLIGHT>"&keyword&"</SPAN>")
%>
<font color="#006633"><%=topic%></font></td>
</tr>
<tr>
<td colspan="4"><%=content%></td>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式