PhoneGap + iOS防止默认滚动操作从输入文本字段开始

Ale*_*lex 5 iphone html5 webkit ios cordova

我遇到了以下问题:

我有一个滚动区域,其中包含输入文本字段列表.

我用

ontouchmove = function(e){ e. preventDefault(); } 
Run Code Online (Sandbox Code Playgroud)

防止页面的全局滚动.除了手势从输入字段开始的情况外,它工作正常.

首次触摸陷阱到输入字段时,如何防止页面的全局滚动?

谢谢.

小智 3

我相信您想使用 addEventListener 函数捕获 touchmove 事件,以便事件不会“冒泡”。尝试这个:

/* This code prevents users from dragging the page */
var preventDefaultScroll = function(event) {
  event.preventDefault();
  window.scroll(0,0);
  return false;
};
document.addEventListener('touchmove', preventDefaultScroll, false);
Run Code Online (Sandbox Code Playgroud)