jQuery Set Cursor Position in Text Area

前端 未结 16 1489
无人共我
无人共我 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:03

    Set the focus before you have inserted the text into the textarea thus?

    $("#comments").focus();
    $("#comments").val(comments);
    

提交回复
热议问题