3

我面临一个烦人的问题。我正在研究一个小 RTE,我现在正试图在元素末尾移动插入符号。

现在,这是我的代码(来自这篇文章How to move cursor to end of contenteditable entity):

我有一些自定义函数可以处理范围和窗口。我几乎可以肯定他们是正确的。

function(contentEditableElement){
    var contentEditableElement = this.getFocusedElement().parentNode;
    if(this.contentDoc.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
{
    range = this.contentDoc.createRange();//Create a range (a range is a like the selection but invisible)
    range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
    range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
    selection = this.win.getSelection();//get the selection object (allows you to change selection)
    selection.removeAllRanges();//remove any selections already made
    selection.addRange(range);//make the range you have just created the visible selection
 }
else if(this.doc.selection)//IE 8 and lower
{ 
    range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
    range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
    range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
    range.select();//Select the range (make it the visible selection
}
}

它在 FF 和 Opera 下运行良好……但在 Chromium 中,插入符号根本不动。

你能帮我找到正确的方法吗?谢谢

4

0 回答 0