0

サイトまたは任意のサイトから 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では正常に動作することを見ましたが、クロムではカーソルを最初から開始します。解決策はありますか?

4

2 に答える 2

0

変更イベントでトリガーすることにより、入力領域にフォーカスできます。

$("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();
   }
});

それが役立つことを願っています、シナン。

于 2009-10-27T23:49:14.697 に答える
0

この質問を見てください: jQuery Set Cursor Position in Text Area

于 2009-10-27T22:03:43.107 に答える