jqueryフォーカス、ただしより正確な位置
-
06-07-2019 - |
質問
サイトまたは任意のサイトから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.
編集済み:
iは、Firefoxでは問題なく動作することを確認しましたが、クロムでは最初からカーソルを開始します。解決策はありますか?
解決
次の質問をご覧ください: 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();
}
});
お役に立てば幸いです、シナン。
所属していません StackOverflow