How does js use scripts to call the keyboard that pops up input on the mobile side?

  node.js, question

Document. GetElementById (). Focus (), I can’t use this without reaction

Unfortunately,No way, the keyboard can only be triggered by user behavior, cannot be triggered by scripts, and has been testediosAndandroidThis is indeed the case.

The so-called user behavior can only be triggered by binding events, and must be triggered before the currentcontext

For example

<input type="text" id="input">
 <button id="click">Click</button>
//Triggered only by user behavior
 document.getElementById('click').addEventListener('click', function() {
 Document. getelementbyid ('input'). focus ()//this will successfully open the keyboard and focus on input
 setTimeout(function() {
 GetElementById ('Input'). Focus ()//This will fail
 }, 2000)

After several tests, it was found that as long asdocument.getElementById('input').focus()IncallbackThere will be failures