4

我想在加载 jQuery mobile 之前通过 AJAX 动态加载页面内容,所以我正在尝试使用该mobileinit事件。但它不起作用。这是我的代码请帮忙

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="http://jquerymobile.com/demos/1.3.0-beta.1/css/themes/default/jquery.mobile-1.3.0-beta.1.css" />
    <script src="js/jquery-1.8.2.min.js"></script>
    <script>
        $(document).bind("mobileinit", function()  {        
            $("#notification").text("Please enter your domain name.");
        });
    </script>
    <script src="js/jquery.mobile-1.3.0.min.js"></script>
    <title>Insert title here</title>
    </head>
    <body>
       <h3 id="notification" style="font-family: fantasy; color: red; text-align: center;"></h3>
    </body>
    </html>
4

2 回答 2

3

这行不通。

触发 mobileinit 事件时,DOM 内容仍为空。Pageinit 是您甚至可以考虑这样做的第一个事件。但更好的是 pagebeforeshow 事件。

$(document).on('pagebeforeshow', '#index', function(){    

});

这是我添加动态生成内容的旧示例:http: //jsfiddle.net/Gajotres/GnB3t/

这是另一个示例,只需单击下一步按钮即可查看动态生成的页面:http: //jsfiddle.net/Gajotres/8jcGb/

于 2013-02-28T15:20:10.607 回答
0

尝试这个

<script src="js/jquery.mobile-1.3.0.min.js"></script>
<script>
function init(){
    $(document).bind("mobileinit", function()  {        
        $("#notification").text("Please enter your domain name.");
    });
}
</script>
<body onLoad="init()">
</body>
于 2013-02-28T14:42:29.537 回答