[英]JQuery Mobile document ready alternative
我花了几个小时尝试调试我创建的jquery移动页面,最后使其工作。 我已经将脚本放在data-role =“ page” class =“ page-map4” div中。 我想知道为什么会这样,我宁愿这对我来说不是魔术。 如果直接访问该页面并不重要,仅当我从另一个JQuery Mobile页面访问它时才如此。
$('.page-map4').live("pageshow", function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('Geolocation not supported');
}
});
问题:当从另一个JQuery Mobile页面导航时,为什么上面的脚本必须在页面数据角色div中才能正常工作?
对于页面事件,我只需在jQuery代码中执行此操作即可。 在将任何文档绑定到$.mobile
全局文件之后,这会在页面的<head>
元素中的<script>
标记集中进行:
$('#YOUR_PAGE_ID').live('pageshow',function(event, ui){
yourGeoCode();
});
您应该使用pageinit事件,请参阅本文“ 使用jQuery Mobile –记住使用pageinit()而不是$(document).ready() ”以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.