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

后端 未结 19 2067
醉话见心
醉话见心 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条回答
  •  星月不相逢
    2020-12-04 07:26

    It looks a little odd, even silly, but this is working for me:

    input.val(lastQuery);
    input.focus().val(input.val());
    

    Now, I'm not certain I've replicated your setup. I'm assuming input is an element.

    By re-setting the value (to itself) I think the cursor is getting put at the end of the input. Tested in Firefox 3 and MSIE7.

提交回复
热议问题