Set mouse focus and move cursor to end of input using jQuery

后端 未结 19 2074
醉话见心
醉话见心 2020-12-04 06:42

This question has been asked in a few different formats but I can\'t get any of the answers to work in my scenario.

I am using jQuery to implement command history wh

19条回答
  •  猫巷女王i
    2020-12-04 07:13

    I have found the same thing as suggested above by a few folks. If you focus() first, then push the val() into the input, the cursor will get positioned to the end of the input value in Firefox,Chrome and IE. If you push the val() into the input field first, Firefox and Chrome position the cursor at the end, but IE positions it to the front when you focus().

    $('element_identifier').focus().val('some_value') 
    

    should do the trick (it always has for me anyway).

提交回复
热议问题