没有滚动javascript导致不工作的文本输入?iPhone Web App

No scroll javascript causes not working text input ? iPhone Web App

本文关键字:输入 文本 iPhone App Web 工作 滚动 javascript      更新时间:2023-09-26

我有一个iPhone web应用程序,我使用这个Javascript使滚动或选择事情不可能:

document.ontouchstart = function(e){
    e.preventDefault();
}

我刚刚发现这段代码也'禁用'一个输入表单:

<input type="text" />

好. .它在那里,但是当你点击它时,没有弹出键盘。

我该如何解决这个问题?

最好的选择是这样做

document.ontouchstart = function(e){
  if(e.target.type == 'text'){
  }
  else {
    e.preventDefault();
  }
}

检测事件目标是否为文本输入