2013-08-28 1 views
0

내 웹 사이트에서 jQuery와 함께 SCEditor를 사용하고 있는데 어떻게 textarea/div의 시작 부분을 기준으로 현재 캐럿 위치를 얻을 수 있습니까? SCEditor 텍스트 영역에서 현재 캐럿 위치를 얻는 방법은 무엇입니까?

내가 좋아하는 일을 시도 :

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

그러나 그것은 단지 나에게 현재 DOM 개체가 아닌 전체 텍스트 영역에 위치를 제공합니다.

내가 달성하려고하는 것은 텍스트 영역에서 캐럿 이후의 모든 텍스트를 제거하는 것입니다. 어쩌면 그것을 할 수있는 또 다른 방법이있을 것입니다.

감사합니다,

답변

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(); 
관련 문제