搜索 多关键词 高亮显示 20

asp做个多字段多关键词搜索,已经成功了,可是想要多个关键词都高亮,不知道有没有高人帮助一下,谢谢======================='-------多字段,多... asp 做个多字段 多关键词 搜索,已经成功了,可是想要多个关键词都高亮,不知道有没有高人帮助一下 ,谢谢

=======================
'------- 多字段,多 关键字查询函数开始 ------
function searchmore(tablename,keyfield,searchtext,filedflag,keywordflag,searchflag,keywordtype)
arrfiled=split(keyfield,",")
maxfiled=ubound(arrfiled)
arrkeyword=split(searchtext," ")
maxlen=ubound(arrkeyword)

if searchflag=1 then
if keywordtype="string" then
searchstart="='"
searchend="'"
else
searchstart="="
searchend=""
end if
else
if keywordtype="string" then
searchstart=" like '%"
searchend="%'"
else
searchstart=" like '%"
searchend="%'"
end if
end if
sql1="("
for j=0 to maxfiled
for i=0 to maxlen
sql1=sql1 & arrfiled(j) & searchstart & arrkeyword(i) & searchend
if i<maxlen then
if keywordflag="and" then
sql1=sql1 & " or "
else
sql1=sql1 & " and "
end if
end if
if i>=maxlen then exit for
next
sql1=sql1 & ")"
if maxfiled>0 and j<maxfiled then
if filedflag="and" then
sql1=sql1 & " and ("
else
sql1=sql1 & " or ("
end if
end if
next
sql="select * from " & tablename & " where " & sql1
sql=sql & " order by id desc"
searchmore=sql
end function
sql=searchmore(tablename,keyfield,searchtext,filedflag,keywordflag,searchflag,keywordtype)

response.write sql
'------- 多字段,多关键字查询函数结束 -------

以上多关键词查询已经实现, 如果一个关键词 变亮也好办,用replace 就可以了。。。。
因为涉及到较多数据表,故我用下面方法实现:
<%
function import_color(source_str,str,out_str_len)

dim temp
temp=source_str

temp_len=len(temp)
str_len=len(str)

if len(str)>len(temp) then
import_color=temp
end if

if str=temp then
temp=replace(temp,str,"<font color='red'>"&str&"</font>")
import_color=temp
end if

if out_str_len mod 2 =1 then
len_pass=int(out_str_len/2)+1
else
len_pass=out_str_len/2
end if

first=instr(temp,str)
if first>0 then
temp1=mid(temp,first,str_len+len_pass)
temp2=left(temp,first-1)
temp2=right(temp2,len_pass)
temp3=temp2&temp1

temp3=ReplaceTest(temp3,str,"<font color='red'>"&str&"</font>")
import_color=temp3
else
import_color=temp
end if

end function
%>
<%
Function ReplaceTest(str1,patrn, replStr)
Dim regEx ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = false ' 设置是否区分大小写。
ReplaceTest = regEx.Replace(str1, replStr) ' 作替换。
End Function
%>

显示页面 这样做 字段1=import_color(字段1,searchtext,150) '取2测150字
======
============
以上是成功查询 多关键词 ,成功高亮一个关键词, 现在问题是 多个关键词怎么高亮?? 高手请赐教 谢谢
根据网上提示 我这样写,

<%
Function import_color(strContent,searchtext)
Dim RegEx
Set RegEx=new RegExp
RegEx.IgnoreCase =True '不区分大小写
RegEx.Global=True

Dim ArrayKeyword,i
ArrayKeyword = Split(searchtext," ")'用空格隔开的多关键字
For i=0 To Ubound(ArrayKeyword)
RegEx.Pattern="("&ArrayKeyword(i)&")"
strContent=RegEx.Replace(strContent,"<font color=red>" & ArrayKeyword(i) & "</font>" )
Next
Set RegEx=Nothing
import_color=strContent
End Function
%>

可是不成功
展开
 我来答
abingpow
2007-01-24 · TA获得超过2205个赞
知道大有可为答主
回答量:2830
采纳率:0%
帮助的人:2241万
展开全部
把关键词替换成 黄底白字 不就行了?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式