Unable to focus an input using JavaScript in IE11

前端 未结 3 1333
孤独总比滥情好
孤独总比滥情好 2021-01-12 14:41

I\'m unable to get IE11 to focus an input element after it is inserted into the DOM. The element won\'t receive text input after being focused, but its placeholder text is n

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 15:10

    I don't think that your issue is coming from the focus() function, I think it's coming from the selector.

    To prove it I just opened my IE11 and tried to focus the SO search input on the top right of the page using the following command:

    document.getElementById('search')[0].focus()
    

    So, just open your IE console (F12) and type that, it should focus the search input. If so, then the issue is coming from the selector which isn't an input as you may think.

    It works on my IE 11.0.9600.17905

提交回复
热议问题