jQuery Set Cursor Position in Text Area

前端 未结 16 1468
无人共我
无人共我 2020-11-21 11:42

How do you set the cursor position in a text field using jQuery? I\'ve got a text field with content, and I want the users cursor to be positioned at a certain offset when

16条回答
  •  囚心锁ツ
    2020-11-21 12:14

    This worked for me on Safari 5 on Mac OSX, jQuery 1.4:

    $("Selector")[elementIx].selectionStart = desiredStartPos; 
    $("Selector")[elementIx].selectionEnd = desiredEndPos;
    

提交回复
热议问题