jQuery Mobile-在页面加载时执行某些操作 [英] jQuery Mobile - Do something on page load

查看:83
本文介绍了jQuery Mobile-在页面加载时执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次页面加载时我都想做些事情.可以修复移动网站在不同设备上的显示方式,因此也需要在AJAX加载中进行.

I want to do something every time a page loads. It's something that fixes the way the mobile site looks on different devices so it needs to happen on AJAX loads too.

此刻,我已经尝试了传统的$(function(){ /*...*/ });方法,但这仅适用于第一次加载,而不适用于随后的AJAX加载.

At the moment, I've tried the traditional $(function(){ /*...*/ }); approach but that only works on the first load, and not subsequent AJAX loads.

我一直在寻找要绑定的正确事件,但是我很难失败.

I've been looking for the right event to bind to but I'm failing pretty hard.

推荐答案

您可以使用JQuery绑定到每个页面"(具有data-role=page属性的div设置)并使用pageshow事件(还有一些其他事件)以及:pagebeforeshowpagehidepagebeforehide).

You can use JQuery to bind to each "page" (div's set with the data-role=page attribute) and use the pageshow event (there are some others as well: pagebeforeshow, pagehide, pagebeforehide).

$(document).delegate('.ui-page', 'pageshow', function () {
    //Your code for each page load here
});

http://api.jquerymobile.com/pageshow/

注意:此答案是为jQuery Mobile 1.0.1编写的,有关更多信息,请参见上面的文档链接.

Note: this answer was written for jQuery Mobile 1.0.1, see the documentation link above for more information.

这篇关于jQuery Mobile-在页面加载时执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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