Javascript 如何使用JS检测用户与phonegap的接触

Javascript 如何使用JS检测用户与phonegap的接触,javascript,android,touch,cordova,Javascript,Android,Touch,Cordova,我正在使用phonegap构建android应用程序 我想检测用户的触摸事件,以便弹出警报。但是,如何从javascript调用ontouch事件 谢谢 下面的示例显示了touchstart和touchend。它演示了附加触摸事件的两种不同方式:元素属性或JavaScript的addEventListener 由于它正在侦听触摸事件,因此这些事件不会在桌面浏览器(支持鼠标事件)上触发。要测试页面,您可以使用Android或iOS模拟器打开它 <!DOCTYPE html> <h

我正在使用phonegap构建android应用程序

我想检测用户的触摸事件,以便弹出警报。但是,如何从javascript调用ontouch事件


谢谢

下面的示例显示了
touchstart
touchend
。它演示了附加触摸事件的两种不同方式:元素属性或JavaScript的
addEventListener

由于它正在侦听触摸事件,因此这些事件不会在桌面浏览器(支持鼠标事件)上触发。要测试页面,您可以使用Android或iOS模拟器打开它

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0;" />
    <style type="text/css">
      a {
        color:black;
        display:block;
        margin:10px 0px;
      }
    </style>

    <script type="text/javascript">
      function onload() {
        document.getElementById('touchstart').addEventListener('touchstart', hello, false);
        document.getElementById('touchend').addEventListener('touchend', bye, false);
      }

      function hello() {
        alert('hello');
      }

      function bye() {
        alert('bye');
      }
    </script>

    <title>Touch Example</title>
  </head>
  <body onload="onload();">
    <h1>Touch</h1>
    <a href="#" ontouchstart="hello();return false;">Attribute: ontouchstart</a>
    <a href="#" ontouchend="bye();return false;">Attribute: ontouchend</a>
    <a href="#" id="touchstart">addEventListener: touchstart</a>
    <a href="#" id="touchend">addEventListener: touchend</a>
  </body>
</html>

a{
颜色:黑色;
显示:块;
利润率:10px 0px;
}
函数onload(){
document.getElementById('touchstart')。addEventListener('touchstart',hello,false);
document.getElementById('touchend')。addEventListener('touchend',bye,false);
}
函数hello(){
警惕(“你好”);
}
函数bye(){
警惕(“再见”);
}
触摸示例
触碰

@mwbrroks我已经试用过了,它与链接/按钮配合使用效果很好。但是我想知道它是否可以在没有任何链接或按钮的空白屏幕上工作。。这意味着只要用户触摸屏幕上的任何位置,就会显示一个弹出窗口。可能吗?:)谢谢你给了我一个窗口。addEventListener(等)虽然还没有完全解决,但你的回答给了我一些开始的方向。但现在还有一个问题,那就是键盘出现了,当我触摸它的按键时,它突然消失了。如何解决此问题?获取jquery mobile,以便从jquery访问不同的触摸事件