android-emulator - jQuery Mobile Listview-列表项onClick在Android模拟器中永远不会触发

原文 标签 android-emulator jquery-mobile cordova

jQuery Mobile Listview - list item onClick never fires in Android Emulator

In a jQuery Mobile listview, I have a series of items:

<ul data-role="listview" id="lv_systems" data-inset="true">
  <li><a href="#page2" data-id="sys1">System 1</a></li>
  <li><a href="#page2" data-id="sys2">System 2</a></li>
    ....
</ul>

In the $(document).ready(), I add a click handlers to each <a> like this (suggested here) (#select_system is the page name):

$(document).ready( function () {         

$('#select_system').live ('pagecreate', function(){
    $('#lv_systems').delegate('li', 'click', function(){
             alert('list item clicked');
    });
});
    $('#lv_systems').listview('refresh');
});

Testing this code works great when testing in a browser (Chrome and Safari), but in the Android Emulator with PhoneGap, the alert message is never displayed which makes it look like the event binding is incorrect.

What am I missing?

Answer

Memo to self: RTFM.

Instead of binding to click with delegate, bind to vclick, i.e.

....
$('#lv_systems').delegate('li', 'vclick', function(){
....

Per the documentation,

Normalized event for handling touch or mouse click events

翻译

在jQuery Mobile listview中,我有一系列项目:

<ul data-role="listview" id="lv_systems" data-inset="true">
  <li><a href="#page2" data-id="sys1">System 1</a></li>
  <li><a href="#page2" data-id="sys2">System 2</a></li>
    ....
</ul>


$(document).ready()中,我向每个<a>添加一个点击处理程序,如下所示(建议here)(#select_system是页面名称):

$(document).ready( function () {         

$('#select_system').live ('pagecreate', function(){
    $('#lv_systems').delegate('li', 'click', function(){
             alert('list item clicked');
    });
});
    $('#lv_systems').listview('refresh');
});


在浏览器(Chrome和Safari)中进行测试时,测试此代码非常有效,但是在带有PhoneGap的Android仿真器中,永远不会显示警报消息,这似乎使事件绑定不正确。

我想念什么?
最佳答案
自我备忘录:RTFM

代替使用委托绑定到click,而是绑定到vclick,即

....
$('#lv_systems').delegate('li', 'vclick', function(){
....


根据文档,


  规范事件,用于处理触摸或鼠标click事件
相关推荐

android - 我可以在Android模拟器上更改鼠标的图片吗?

java - 应用程序的旧副本显示在Android Emulator上(使用Eclipse IDE)

android - 如果我尝试修复GPS坐标,则Android模拟器会重启

android-emulator - Android模拟器上的示例联系人进行测试?

java - 同时输入if AND else语句?

android - 为什么在onCreate()之外显示Toast会使我的应用程序崩溃?

android - 如何在Xamarin的新“ Android设备管理器”中禁用快速启动?

android - Android模拟器错误缺少WinHvPlatform.dll

android - 如何从android模拟器访问主机的网络

android - 在Espresso测试期间发送模拟器控制台命令