put cursor at end of text input's value

后端 未结 5 2106
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 07:37

So, currently I have a text-input-field with a value that is also autofocused.

On page load, the value is selected / highlighted. Is there a way I can put the cursor at

5条回答
  •  [愿得一人]
    2021-02-02 07:58

    You can add this parameter to your text input field:

    onmouseover="this.setSelectionRange(this.value.length,this.value.length);"
    onfocus="this.setSelectionRange(this.value.length,this.value.length);"
    

    NB: Works well under Chromium in 2017.

提交回复
热议问题