我想使用Rangy突出显示ul的li元素中的单词This
:
<ul>
<li>T<strong>hs is bea</strong>utiful.
<br>
</li>
</ul>
在运行时,我最后用一个单独的li包围着This
这个词,另一个li包裹着剩余的内容is beautiful
如何停止在单词This
我的代码如下:
$scope.highlightTagStrings=function() {
var selection,selectedRange;
selection = rangy.getSelection(); //console.log(rSel);
var txt = selection.toHtml();
selectedRange = selection.getRangeAt(0);
selectedRange.deleteContents();
//var node = selectedRange.createContextualFragment('<span class="hilite ' + evalNum + '" name="' + sSel + '~' + eSel + '">' + txt + '</span>');
var node = selectedRange.createContextualFragment('<span style="background-color:pink" class="startIndex-' + startIndex + ' endIndex-' + endIndex + '">' + txt + '</span>');
selectedRange.insertNode(node);
selection.removeAllRanges();
return;
}
有人可以帮我解决这个问题吗?