$.focus() not working

后端 未结 14 1163
走了就别回头了
走了就别回头了 2020-11-27 02:48

The last example of jQuery\'s focus() documentation states

$(\'#id\').focus()

should make the input focused (active). I can\'t seem to get

14条回答
  •  感情败类
    2020-11-27 03:04

    Add a delay before focus(). 200 ms is enough

    function focusAndCursor(selector){
      var input = $(selector);
      setTimeout(function() {
        // this focus on last character if input isn't empty
        tmp = input.val(); input.focus().val("").blur().focus().val(tmp);
      }, 200);
    }
    

提交回复
热议问题