1
我正在修复编辑器,并突出显示文本问题。突出显示文本问题
我得到这个代码,检查你有什么用户突出显示(下面的代码中详细介绍):
function getSelectionHTML()
{
var iframe = document.getElementById(theEditorID);
var win, doc = iframe.contentDocument;
if(doc)
win = doc.defaultView;
else
{
win = iframe.contentWindow;
doc = win.document;
}
var userSelection;
if(win.getSelection)
{
userSelection = win.getSelection();
if(userSelection.getRangeAt)
var range = userSelection.getRangeAt(0);
else
{
var range = document.createRange();
range.setStart(userSelection.anchorNode, userSelection.anchorOffset);
range.setEnd(userSelection.focusNode, userSelection.focusOffset);
}
var clonedSelection = range.cloneContents();
var div = document.createElement('div');
div.appendChild(clonedSelection);
callIcons(div.innerHTML);
}
else if(doc.selection)
{
userSelection = document.selection.createRange();
callIcons(userSelection.htmlText);
}
};
当用户突出显示一些大胆的文字和其他一些斜体文字,我得到这样的输出:
<b>some text</b><i>some other text</i>
但是,当用户只突出粗体文字我得到这个输出(没有“大胆”标签):
some text
您可以在此查看,直播 - http://brownfolder.com/06/ 突出显示一些文字后,您会看到提醒。
你有什么想法我该如何解决这个问题?
在此先感谢。
可能更容易使用像闭包一样的范围库:http://code.google.com/p/closure-library/source/browse/trunk/closure/goog /dom/range.js?r=2 – Annie 2011-02-23 02:55:47