Set keyboard caret position in html textbox

后端 未结 9 2541
时光说笑
时光说笑 2020-11-22 00:02

Does anybody know how to move the keyboard caret in a textbox to a particular position?

For example, if a text-box (e.g. input element, not text-area) has 50 charact

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 00:14

    If you need to focus some textbox and your only problem is that the entire text gets highlighted whereas you want the caret to be at the end, then in that specific case, you can use this trick of setting the textbox value to itself after focus:

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

提交回复
热议问题