2013-08-28 46 views
0

我在我的網站中沿着jQuery使用SCEditor,我不知道如何才能獲得相對於textarea/div開頭的當前插入符的位置?如何在SCEditor textarea中獲取當前的脫字號位置?

我試過的東西:

$J('#textarea').sceditor('instance').getRangeHelper().selectedRange().startOffset 

,但只給了我相對於當前DOM對象,而不是整個文本區域的位置。

我想要完成的是從textarea刪除插入符號後的所有文本。也許有另一種方式來做到這一點。

感謝,

回答

0

您可以使用rangeHelper().saveRange()處插入,從他們開始和選擇結束和工作的標記。

例如爲:

var sceditor = $("textarea").sceditor("instance"); 

// Inserts spans with the ID #sceditor-end-start and #sceditor-end-marker 
// at the start and end of the current selection 
sceditor.getRangeHelper().saveRange(); 

// Get the DOM node for #sceditor-end-marker and remove all 
// nextSiblings and parent nextSiblings from the editor 
// which will remove everything after the end of the selection 
var node = sceditor.getBody().find('#sceditor-end-marker').get(0); 
while (node) { 
    while (node.nextSibling) 
     node.parentNode.removeChild(node.nextSibling); 

    node = node.parentNode; 
} 

// Restores the selection back to the positions of the 
// #sceditor-end-start and #sceditor-end-marker markers 
sceditor.getRangeHelper().restoreRange(); 
sceditor.focus();