jQuery mobile $(document).ready 等价物 [英] jQuery mobile $(document).ready equivalent

查看:19
本文介绍了jQuery mobile $(document).ready 等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ajax 导航页面中,用于执行初始化 javascript 的经典文档就绪"表单根本不会触发.

在 ajax 加载的页面中执行某些代码的正确方法是什么?

(我的意思是,不是我的 ajax...它是 jquery 移动页面导航系统将我带到该页面)

好吧,我确实怀疑过类似的事情...非常感谢 =) 但是...它仍然不起作用,这是我的代码:

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

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>我的页面</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){警报('ciao');});<身体><div data-role="页面"><div data-role="header" data-position="fixed"><h1>购物车</h1>

<div data-role="内容">阿斯达

我需要指定 div id 吗?

解决方案

我花了一些时间研究同样的问题,因为此时 JQM 文档还不是很详细.下面的解决方案对我来说很好:

您必须实现自己的检查流程以防止多次初始化,因为上面的代码将在每次页面更改时运行

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

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

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

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>

Do I need to specify the div id?

解决方案

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>

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 $(document).ready 等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆