我想将 SpanElement 插入 DOM 的当前(光标)位置。我使用这个 VB6 函数:
Private Function InsertSpan(Tipo As String, Nome As String)
Dim oSpan As MSHTML.HTMLSpanElement
Dim oCurElement As MSHTML.IHTMLElement
Dim oDOM As MSHTML.HTMLDocument
Set oDOM = HTMLEdit.DOM
Set oCurElement = oDOM.activeElement
Set oSpan = oDOM.createElement("SPAN")
oSpan.Id = Tipo & "." & Nome
oSpan.className = Tipo
oSpan.innerHTML = "<b><font size='3' color='#000000'></font></b>"
oSpan.lastChild.lastChild.innerText = "[" & Nome & "]"
oSpan.Style.backgroundColor = "yellow"
oSpan.hideFocus = True
oSpan.contentEditable = "false"
oSpan.Style.verticalAlign = "middle"
oCurElement.appendChild oSpan
oDOM.parentWindow.Focus
End Function
但 SpanElement 附加到当前元素。谢谢,路易吉。