jQuery Mobile的$(文件)。就绪相当于 [英] jQuery mobile $(document).ready equivalent

查看:129
本文介绍了jQuery Mobile的$(文件)。就绪相当于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AJAX导航页,经典的文档准备好的形式进行初始化JavaScript的根本不火。

in ajax navigation pages, the classic "document ready" form for performing initialization javascript simply doesn't fire.

什么是正确的方法来执行一些code在Ajax加载的页面?

What's the right way to execute some code in an ajax loaded page?

(我的意思是,不是我的阿贾克斯......这是jQuery Mobile的页面导航系统,它使我的页面)

(I mean, not my ajax... it's the jquery mobile page navigation system which brings me to that page)

好吧,我做了犯罪嫌疑人这样的事情......非常感谢=)可是......它仍然无法正常工作,这是我的code:

Ok, I did suspect something like that... thanks a lot =) But... it still doesn't work, here's my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>mypage</title>

    <link rel="stylesheet" href="jquery.mobile-1.0a4.min.css" />
    <script type="text/javascript" src="jquery-1.5.min.js"></script>
    <script type="text/javascript" src="jquery.mobile-1.0a4.min.js"></script>
    <script type="text/javascript">
        $('div').live('pageshow',function(event, ui){
          alert('ciao');
        });
    </script>

</head>

<body>

    <div data-role="page">

        <div data-role="header" data-position="fixed">
            <h1>Shopping Cart</h1>
        </div>

        <div data-role="content"> asd


        </div>

    </div>

</body>

我是否需要指定分区ID?

Do I need to specify the div id?

推荐答案

我花了一些时间在研究相同的,因为JQM文档是不是在这一点上是非常详细的。下面的解决方案为我工作正常:

I spent some time on researching the same since JQM docs are not very detailed at this point. Solution below works fine for me:

<script type="text/javascript">
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
    // code to execute on each page change
});
</script>

您必须实现以自己的检查流程,以prevent多个初始化,因为code以上将运行在每一页变化

You have to implement your own checking flow in order to prevent multiple initialization since the code above will run on every page change

这篇关于jQuery Mobile的$(文件)。就绪相当于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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