focus() not working in safari or chrome

前端 未结 6 2067
别那么骄傲
别那么骄傲 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:44

    Your problem is likely that you're not appending a DOM object, you're appending explicit HTML to your page -- and I doubt that Safari is updating the DOM behind the scenes.

    Try to use the actual DOM methods like document.createElement() to append your input to the DOM, as described in a number of places (such as here or here or here), and then see if the Safari problem persists.

    All that said, the way that you describe the issue arising -- on clicks but not tabs, for example -- would argue that the problem isn't going to be this... so now I'm curious. (In any event, using DOM methods is really the right way to add elements, so it's not a bad idea to do it anyway.)

提交回复
热议问题