jQuery Mobile里xxx怎么用呀? (事件篇)

jQuery Mobile里$(document).ready()怎么用呀?

相关链接:

注意事项:

    • Use $(document).bind('pageinit/pageshow'), not $(document).ready()
    • 默认设置下,jQueryMobile网站第一个页面之后的所有页面都是使用AJAX去加载的,而document.ready只会在第一个页面加载时执行,that's why not document.ready.
    • 相对应的,pageinit/pageshow事件则像是加载页面AJAX代码的一个回调(callback)函数,请求成功后便触发执行

jQuery Mobile里mobileinit event怎么用呀?

相关链接:

mobileinit事件的作用:

    • 更改默认设置(To override default settings)
    • 在page加载之前绑定事件处理函数(bind pageshow/pageinit event handlers before page is loaded)

注意事项:

    • mobileinit事件处理函数的代码一定要放在在jquery加载之后,jquerymobile加载之前
    • <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
      <script>
      $(document).on("mobileinit", function(){
        $(document).on('pageshow', 'div:jqmData(role="page"), div:jqmData(role="dialog")', function(event){
          //pageshow handler goes here
        });
        $(document).on('pageinit', function() {    
          //pageinit handler goes here
        });
      });  
      </script> 
      <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>

       

jQuery Mobile里page事件触发顺序是怎样的?

First all events can be found here: http://api.jquerymobile.com/category/events/

    • pagebeforeloadpageload and pageloadfailed are fired when an external page is loaded
    • pagebeforechangepagechange and pagechangefailed are page change events. These events are fired when a user is navigating between pages in the applications.
    • pagebeforeshowpagebeforehidepageshow and pagehide are page transition events. These events are fired before, during and after a transition and are named.
    • pagebeforecreatepagecreate and pageinit are for page initialization.
    • pageremove can be fired and then handled when a page is removed from the DOM

Page loading jsFiddle example: http://jsfiddle.net/Gajotres/QGnft/

(以上内容copy自http://stackoverflow.com/questions/14468659/jquery-mobile-document-ready-vs-page-events,有那么好的讲解我为什么不用!)

转载于:https://www.cnblogs.com/mrdo/p/FAQ_jQueryMobile.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值