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

查看:20
本文介绍了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.(iediv with data-role="page">).live() 将您定义的包含alert 的函数附加到aboutPagepageinit 事件.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.

简而言之,您的代码所做的是

So in short What your code does is

它会在aboutPage初始化时执行alert语句

it will execute the alert statement when aboutPage is initialized

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

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天全站免登陆