2011-12-22 4 views

답변

0

구현에 대해서는 아래 링크를 참조하십시오. 당신은 캐럿의 인덱스를 얻을 수 있도록 keydown 이벤트에 getCaret 함수를 호출 할 수 있습니다 :

https://stackoverflow.com/a/263796/639960

2

네, 있습니다.


textarea.addEventListener('keydown', function(){ 
    console.log(textarea.selectionEnd); //The position of the cursor. If something is selected, then the position of the end of the selection. 
}, false); 

이 기능은 IE 작동하지 않습니다. IE에서는 document.createTextRange()을 사용해야합니다.

+0

Firefox, Safari에서 작동한다는 것을 알고 있습니다. 그것은 IE에서 작동합니까? – Akhil

+0

@Akhil 대답에서 말했듯이, 그렇지 않습니다. –

+0

미안하지만, 나 ... 그 부분을 놓쳤다! :) – Akhil

관련 문제