Set keyboard caret position in html textbox

后端 未结 9 2560
时光说笑
时光说笑 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:07

    function SetCaretEnd(tID) {
        tID += "";
        if (!tID.startsWith("#")) { tID = "#" + tID; }
        $(tID).focus();
        var t = $(tID).val();
        if (t.length == 0) { return; }
        $(tID).val("");
        $(tID).val(t);
        $(tID).scrollTop($(tID)[0].scrollHeight); }
    

提交回复
热议问题