프로그래밍
[JS & jQuery] 커서를 input box 의 맨 뒤에 위치시키기
FelixDies
2015. 2. 8. 19:09
사용자 입력을 받을 때, 사용자가 순서대로 입력하도록 input box 의 커서를 맨 뒤에 위치시키는 방법입니다.
참고
// 클릭 또는 키보드 입력 시 target input box 내에서 커서를 맨 뒤로 옮긴다.
$('#targetInputBox').on("click keyup", function (e) {
// IE
if (this.createTextRange) {
var range = this.createTextRange();
range.move('character', this.value.length); // input box 의 글자 수 만큼 커서를 뒤로 옮김
range.select();
}
else if (this.selectionStart || this.selectionStart== '0')
this.selectionStart = this.value.length;
});