focus() not working in safari or chrome

前端 未结 6 2089
别那么骄傲
别那么骄傲 2020-11-30 11:25

I have a div that has been given a tabindex, when the div is focused(click or tabbed to) it does the following:

inserts an input into itself, gives the input focus

6条回答
  •  悲&欢浪女
    2020-11-30 11:40

    I got the answer on my own, it might seem weak, and too simple, but it works.

    Ready for this awesomeness..?

    Just add a timer of 0 to the focus...for some reason it just gives it enough time to fully load the input into the DOM.

    function recipientDivHandler(code, element) {
      $("#recipientsDiv").append('');
      setTimeout(function() {
        $("#toInput").focus();
      }, 0);
    }
    

    If someone else can further explain this or has a better answer please feel free to take the stage :-)

提交回复
热议问题