The problem that the focus of js's focus () is not triggered.

problem description

jsinputfocus()textarea

the environmental background of the problems and what methods you have tried

I encountered the problem that focus () does not trigger while debugging the front-end code. In the example in the figure below, I tried to get the focus of the codeshelper search box, but it didn"t work.

related codes

document.getElementById("searchBox").focus()

what result do you expect? What is the error message actually seen?

do you want to know that focus () cannot take effect until the DOM is loaded? How to get the focus of the text box simply and efficiently.

Nov.14,2021

el.onfocus = function () {dosomething. }

Menu