【问题标题】:jQuery mobile events not firing at alljQuery 移动事件根本没有触发
【发布时间】:2014-04-22 01:23:48
【问题描述】:

我是移动编程新手,已经面临这个问题。

使用 jQuery mobile 时,只有像“click”这样的普通事件起作用,而像“tap”或“taphold”这样的移动事件不起作用。我错过了什么?我已经找到了一些关于在链接 jQuery 文件时使用正确顺序的提示,但我没有看到任何错误。

<script src="js/jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<link rel="stylesheet" type="text/css" href="css/map.css"></link>
<script src="http://open.mapquestapi.com/sdk/leaflet/v0.1/mq-map.js?key=**"></script>
<script src="http://open.mapquestapi.com/sdk/leaflet/v0.1/mq-geocoding.js?key=**"></script>
<script src="js/index.js"></script>
<script src="js/jquery.mobile.js" type="text/javascript"></script>

<script type="text/javascript">
window.onload = function() {
    loading('show');
    map = L.map('map', {
        layers: MQ.mapLayer(),
        center: [51.137140, 10.239258],
        zoom: 6
    });

    $(document).on("tap", "#map", function(e) {alert("lel");} );
    loading('hide');
};
</script>

另一方面,这是可行的:

$(document).on("click", "#map", function(e) {alert("lel");} );

【问题讨论】:

  • 您不应该使用$(document).on('pageinit', function() { .. 而不是window.onload 吗?
  • 不幸的是,这并没有改变什么

标签: jquery events jquery-mobile


【解决方案1】:

tap 似乎没有 '.on' 的长格式

它只有提供回调函数的格式。试试

$("#map").on("tap",function(e) {alert("lel");} );

编辑

看起来长格式也可以正常工作。你能检查一下你是否有正确的图书馆吗?我无法下载地图,但它似乎在 div 上运行良好。

我添加了点击和点击。有趣的是,在 Android Chrome 上,如果先检测到点击,则可以停止点击,但如果先检测到点击,则点击总是在之后触发。

http://plnkr.co/edit/vBS1KnKkcQZkF7CP5tsJ?p=preview

【讨论】:

  • 您的 sn-p 为我指明了正确的方向。我忘了链接 jquery CSS 文件。谢谢!
猜你喜欢
  • 1970-01-01
  • 2013-01-02
  • 1970-01-01
  • 2013-12-07
  • 1970-01-01
  • 2017-06-09
  • 2010-11-20
  • 1970-01-01
  • 2012-02-14
相关资源
最近更新 更多