문제

사이트 나 사이트에서 Focus () 답변을 쉽게 찾을 수 있습니다. 그러나 내가 알고 싶은 것은 입력 상자 안에 방금 삽입 한 후 포커스를 어떻게 사용할 수 있습니까?

$("input").val('@user').focus(); // this goes to start of the input box and foucs from start, but i want it to focus after the @user

$("input").val('@user today i did new things').focus(5); // i added 5 in focus method, obviously its not supported yet!, but the idea behind is, to focus it after @user from complete word.

편집 :

방금 Firefox에서 잘 작동하는 것을 보았지만 Chrome에서는 처음부터 커서를 시작합니다. 해결책이 있습니까?

도움이 되었습니까?

해결책

이 질문을 살펴보십시오. jQuery 텍스트 영역에서 커서 위치

다른 팁

입력 영역에 초점을 맞출 수 있습니다.

$("input").change(function(){
   $(this).focus();
});

그리고 유형의 문자 수를 확인하려면 콜백을 제어 할 수 있습니다.

//will focus if typed text's length is greater than 5
$("input").change(function(){
   if($(this).val().length > 5){
     $(this).focus();
   }
});

도움이되기를 바랍니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top