网页中高亮关键字如何让它不高亮?

jiangqiaohua 2008-10-12 10:06:47
网页中高亮关键字如何让它不高亮?

Public Sub HightLight2(nKey$, nDoc As MSHTML.HTMLDocument, Optional ByVal IsLight As Boolean = True, Optional beforeTag$ = vbNullString, Optional afterTag$ = vbNullString)
On Error GoTo due
Dim tBody As MSHTML.HTMLBody
Dim oRange As MSHTML.IHTMLTxtRange

If LenB(beforeTag) = 0 Then
beforeTag = "<span style='background-color:yellow'>"
End If
If LenB(afterTag) = 0 Then
afterTag = "</span>"
End If

Set tBody = nDoc.body
If Not tBody Is Nothing Then
Set oRange = tBody.createTextRange
If Not oRange Is Nothing Then
oRange.collapse
oRange.Select
Debug.Print "cretee range"
'height light the keyword ,jerry
If IsLight Then
While oRange.findText(nKey)
Call oRange.pasteHTML(beforeTag & oRange.Text & afterTag)
Call oRange.moveStart("character", 1)
Wend
Else

While oRange.findText(nKey)
Call oRange.pasteHTML(nKey)
Call oRange.moveStart("character", 1)
Wend
End If
End If
End If
Exit Sub

due:
Debug.Print "hl2 err:"; Err.Description, Err.Number
Resume Next
End Sub
这是高亮关键字的代码
如何让它不高亮?
...全文
186 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiangqiaohua 2008-10-14
  • 打赏
  • 举报
回复
我尝试过 替换

但是 Call oRange.pasteHTML(beforeTag & oRange.Text & afterTag)
方法
只有把 文字替换成HTML 的方法
没有把HTML方法替换成文字的方法
ooohooo 2008-10-14
  • 打赏
  • 举报
回复
把高亮的代码全部Replace成""再Write。我不懂Webbrowser的Write代码的方法。因为我没有需要用过这个的时候所以不熟悉。
jiangqiaohua 2008-10-13
  • 打赏
  • 举报
回复
没有人知道吗

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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