jQuery Mobile - 绑定到 pageinit 事件
我试图理解以下 jQuery Mobile 示例。
$( '#aboutPage' ).live( 'pageinit',function(event){
alert( 'This page was just enhanced by jQuery Mobile!' );
});
在这种情况下,#aboutPage
是什么? pageinit
绑定到的对象是什么?
I am trying to understand the following jQuery Mobile example.
$( '#aboutPage' ).live( 'pageinit',function(event){
alert( 'This page was just enhanced by jQuery Mobile!' );
});
What is #aboutPage
in this context? What is the object pageinit
is binding to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
aboutPage
应该是页面的 id。(iediv 与data-role="page"
)。live()
附加您拥有的功能定义其中包含对aboutPage
的pageinit
事件的警报
。当页面被打开时,会在页面上触发pageinit
已初始化。简而言之,您的代码的作用是
即使页面不在视图中,也可能会被初始化。因此,即使在您进入该页面之前,该页面的
pageinit
div 将被触发。如果您正在加载另一个 html 文件作为新页面pageinit
,则仅当您将该页面加载到视图中时才会触发该页面。所以,在您的情况下,如果您想做某事当你的 div 进入视图时,你可以尝试pagebeforeshow
和pageshow
。pagebeforeshow
将在动画开始前在新页面上触发,pageshow
在动画结束后触发。aboutPage
should be the id of the page.(i.e.div withdata-role="page"
).live()
attaches the funcion you have defined which contains thealert
to thepageinit
event ofaboutPage
.pageinit
is triggered on a page when the page is initialized.So in short What your code does is
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 pagepageinit
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 thepagebeforeshow
andpageshow
.pagebeforeshow
will be triggered on the new page before animation starts andpageshow
after animation is over.