jQuery Mobile-绑定到pageinit事件 [英] jQuery Mobile - binding to pageinit event

查看:115
本文介绍了jQuery Mobile-绑定到pageinit事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解以下 jQuery Mobile 示例.

I am trying to understand the following jQuery Mobile example.

$( '#aboutPage' ).live( 'pageinit',function(event){
  alert( 'This page was just enhanced by jQuery Mobile!' );
});

在这种情况下,#aboutPage是什么? pageinit绑定到的对象是什么?

What is #aboutPage in this context? What is the object pageinit is binding to?

推荐答案

aboutPage应该是页面的ID.(即带有data-role="page"的div).live()附加您定义的包含alertaboutPagepageinit事件.在初始化页面时在页面上触发pageinit.

aboutPage should be the id of the page.(i.e.div with data-role="page").live() attaches the funcion you have defined which contains thealert to the pageinit event of aboutPage.pageinit is triggered on a page when the page is initialized.

简而言之,您的代码是

在初始化aboutPage时将执行警报语句

it will execute the alert statement when aboutPage is initialized

即使页面不在视图中,该页面也可能会被初始化.因此,即使在您进入该页面之前,div的pageinit也会被触发.如果您要加载另一个html文件作为新页面pageinit仅当您将该页面加载到视图中时才会触发该页面.因此,在您的情况下,如果您想在div进入视图时执行某些操作,则可以尝试pagebeforeshowpageshow.在动画开始之前在新页面上触发,在动画结束之后在pageshow上触发.

The page might be initialized even if it is not in view.So even before you go to that page,the pageinit of the div will be triggered.If you are loading another html file as the new page pageinit for that page will be triggered only when you load that page into view.So,in your case if you want to do something when your div comes into view,you can try the pagebeforeshow and pageshow.pagebeforeshow will be triggered on the new page before animation starts and pageshow after animation is over.

这篇关于jQuery Mobile-绑定到pageinit事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆