[bug solution] The solution to the problem that the ios input box cannot be automatically focused and is blocked by the keyboard after focusing

foreword

When doing some comments or other similar functions, we often encounter the following two problems:

  1. Maybe we want to automatically focus the input box at the bottom when the comment icon is clicked, but we found that the focus event calling the input box does not work.
  2. After the input box is focused, it is blocked by the pop-up keyboard, and you have to slide down to see the input box

solve

 setTimeout(() => {
    
    
     //解决第一个问题,myInput是获取到的输入框元素
     myInput.value.focus()    
    
     //解决第二个问题
     document.body.scrollTop = document.body.scrollHeight;   
  }, 100);

Guess you like

Origin blog.csdn.net/qq_38974163/article/details/123277408