不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
加亮关键字
编辑:dnawo 日期:2007-03-20
一、JS法
1、单个关键字加亮
2、多个关键字加亮
二、ASP法
1、用Replace实现
此法没有考虑到内容中的HTML代码。
2、用Instr、Mid等函数实现(函数摘自PJBLOG)
此法考虑到了内容中的HTML,但如果内容中碰巧包含有<的话,搜索结果就不是很准确,总得来说,这是众多方法中较好的了。
1、单个关键字加亮
复制内容到剪贴板
程序代码

<div id="txt">
用JS让文章内容指定的关键字加亮
是这样的..
现在有这些关键字:美容,生活,购物
当在文章里头出现这些关键字,就把它加亮显示..
文章是生成静态页面的,而这些关键字是能随时更新的,所以我想用JS来实现...
</div>
<script language="JavaScript">
document.getElementById("txt").innerHTML = document.getElementById("txt")..innerHTML.replace(/文章/gi,"<font color=red>文章</font>");
</script>
用JS让文章内容指定的关键字加亮
是这样的..
现在有这些关键字:美容,生活,购物
当在文章里头出现这些关键字,就把它加亮显示..
文章是生成静态页面的,而这些关键字是能随时更新的,所以我想用JS来实现...
</div>
<script language="JavaScript">
document.getElementById("txt").innerHTML = document.getElementById("txt")..innerHTML.replace(/文章/gi,"<font color=red>文章</font>");
</script>
2、多个关键字加亮
复制内容到剪贴板
程序代码

<div id="txt">
用JS让文章内容指定的关键字加亮
是这样的..现在有这些关键字:美容,生活,购物
当在文章里头出现这些关键字,就把它加亮显示..
文章是生成静态页面的,而这些关键字是能随时更新的,所以我想用JS来实现...
</div>
<script language="JavaScript">
document.getElementById("txt").innerHTML = document.getElementById("txt").innerHTML.replace(/(文章)|(关键字)|(功能)/gi,"<font color=red>$1$2$3</font>");
</script>
用JS让文章内容指定的关键字加亮
是这样的..现在有这些关键字:美容,生活,购物
当在文章里头出现这些关键字,就把它加亮显示..
文章是生成静态页面的,而这些关键字是能随时更新的,所以我想用JS来实现...
</div>
<script language="JavaScript">
document.getElementById("txt").innerHTML = document.getElementById("txt").innerHTML.replace(/(文章)|(关键字)|(功能)/gi,"<font color=red>$1$2$3</font>");
</script>
二、ASP法
1、用Replace实现
复制内容到剪贴板
程序代码

<%
Dim i, KeyWords, ArrKeyWords
Dim strLongWords
strLongWords = "日前,建设部表示尚未公布住房建设规划的城市,务必在12月20日前全面完成编制、公布和备案工作;尚未建立廉租住房制度的城市,必须在2006年年底前建立并实施。目前全国尚有65%的地级以上城市、91.1%的县级城市未公布住房建设规划的情况。"
If Request.QueryString("KeyWords")<>"" Then
KeyWords = Request.QueryString("KeyWords")
ArrKeyWords = Split(KeyWords, " ",-1,1)
For i = LBound(ArrKeyWords) To UBound(ArrKeyWords)
strLongWords = Replace(strLongWords, ArrKeyWords(i), "<font color='#FF0000'>" & ArrKeyWords(i) & "</font>")
Next
End If
%>
Dim i, KeyWords, ArrKeyWords
Dim strLongWords
strLongWords = "日前,建设部表示尚未公布住房建设规划的城市,务必在12月20日前全面完成编制、公布和备案工作;尚未建立廉租住房制度的城市,必须在2006年年底前建立并实施。目前全国尚有65%的地级以上城市、91.1%的县级城市未公布住房建设规划的情况。"
If Request.QueryString("KeyWords")<>"" Then
KeyWords = Request.QueryString("KeyWords")
ArrKeyWords = Split(KeyWords, " ",-1,1)
For i = LBound(ArrKeyWords) To UBound(ArrKeyWords)
strLongWords = Replace(strLongWords, ArrKeyWords(i), "<font color='#FF0000'>" & ArrKeyWords(i) & "</font>")
Next
End If
%>
此法没有考虑到内容中的HTML代码。
2、用Instr、Mid等函数实现(函数摘自PJBLOG)
复制内容到剪贴板
程序代码

'*************************************
'加亮关键字
'*************************************
Function highlight(byVal strContent,byRef arrayWords)
Dim intCounter,strTemp,intPos,intTagLength,intKeyWordLength,bUpdate
if len(arrayWords)<1 then highlight=strContent:exit function
For intPos = 1 to Len(strContent)
bUpdate = False
If Mid(strContent, intPos, 1) = "<" Then
On Error Resume Next
intTagLength = (InStr(intPos, strContent, ">", 1) - intPos)
if err then
highlight=strContent
err.clear
end if
strTemp = strTemp & Mid(strContent, intPos, intTagLength)
intPos = intPos + intTagLength
End If
If arrayWords <> "" Then
intKeyWordLength = Len(arrayWords)
If LCase(Mid(strContent, intPos, intKeyWordLength)) = LCase(arrayWords) Then
strTemp = strTemp & "<span class=""high1"">" & Mid(strContent, intPos, intKeyWordLength) & "</span>"
intPos = intPos + intKeyWordLength - 1
bUpdate = True
End If
End If
If bUpdate = False Then
strTemp = strTemp & Mid(strContent, intPos, 1)
End If
Next
highlight = strTemp
End Function
'加亮关键字
'*************************************
Function highlight(byVal strContent,byRef arrayWords)
Dim intCounter,strTemp,intPos,intTagLength,intKeyWordLength,bUpdate
if len(arrayWords)<1 then highlight=strContent:exit function
For intPos = 1 to Len(strContent)
bUpdate = False
If Mid(strContent, intPos, 1) = "<" Then
On Error Resume Next
intTagLength = (InStr(intPos, strContent, ">", 1) - intPos)
if err then
highlight=strContent
err.clear
end if
strTemp = strTemp & Mid(strContent, intPos, intTagLength)
intPos = intPos + intTagLength
End If
If arrayWords <> "" Then
intKeyWordLength = Len(arrayWords)
If LCase(Mid(strContent, intPos, intKeyWordLength)) = LCase(arrayWords) Then
strTemp = strTemp & "<span class=""high1"">" & Mid(strContent, intPos, intKeyWordLength) & "</span>"
intPos = intPos + intKeyWordLength - 1
bUpdate = True
End If
End If
If bUpdate = False Then
strTemp = strTemp & Mid(strContent, intPos, 1)
End If
Next
highlight = strTemp
End Function
此法考虑到了内容中的HTML,但如果内容中碰巧包含有<的话,搜索结果就不是很准确,总得来说,这是众多方法中较好的了。
评论: 1 | 引用: 0 | 查看次数: 5075
发表评论
请登录后再发表评论!