hillpig的个人博客分享 http://blog.sciencenet.cn/u/hillpig 畅想ing,思考ing,前行ing Email:bluevaley@gmail.com

博文

使用jquerymobile时,如何让data-rel="back" 返回时不再刷新页面

已有 15431 次阅读 2015-2-18 16:03 |个人分类:js|系统分类:科研笔记| quot, amp, jquerymobile, ready

先说结论:

$(document).on('ready', function(){  

//这里是你的事件

});

下面我们来分析一下,首先看一下page的事件顺序,可参考:

http://www.gajotres.net/page-events-order-in-jquery-mobile-version-1-4-update/

http://www.gajotres.net/page-events-order-in-jquery-mobile/

这里做个截图:


注意上图中的complete对应的是ready()事件。

可以利用

event.zip (或者看这里:http://jsfiddle.net/Gajotres/QGnft/

里面的方法来查看事件顺序:


pagebeforechange!!page1.html:53
page1 - pagebeforecreate!!page1.html:40
page1 - pagecreate!!page1.html:44
page1 - pageinit!!page1.html:48
page1 - pagebeforeshow!!page1.html:73
page1 - pageshow!!page1.html:77
pagechange!!page1.html:57
document ready!!page1.html:88
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.jquery.js:6846
window.onload!!!

我给增加了一个window的onload事件,注意:window和document的事件区别,参考:

http://blog.sina.com.cn/s/blog_74f1a3280102uyxp.html

一个完整的主页面调用为:

<a href="detailactivity.html?id=8" data-ajax="true" data-transition="flip" id="8"><img src="http://www.gobaby.im:9090/gobaby/img/icon/todo.png" class="activity_img" height="200px">

返回页面为:

<a href="javascript:void(0);" data-rel="back" class="ui-btn ui-icon-arrow-l ui-btn-icon-notext ui-corner-all">返回


另外判断是否返回的js代码为:

$(window).on("navigate", function(event, data) {

   alert("navigate");

   if (data.state.direction == "back") {

       alert("User navigated back.");

   }

});


其他一些有用的链接:

http://api.jquery.com/ready/

http://demos.jquerymobile.com/1.2.0/docs/api/events.html

http://api.jquerymobile.com/mobileinit/

http://stackoverflow.com/questions/14468659/jquery-mobile-document-ready-vs-page-events/14469041#14469041

http://stackoverflow.com/questions/25175350/is-there-an-event-that-occurs-after-data-rel-back


加我私人微信,交流技术。




https://blog.sciencenet.cn/blog-419883-868873.html

上一篇:错误解决: Failed to find: play-service-wearable+
下一篇:如何用jquery获取当前页面url传入的参数
收藏 IP: 223.72.72.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-12 17:41

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部