jQuery Mobile on('pageinit')没有解雇

时间:2013-03-23 20:49:48

标签: jquery jquery-mobile

使用最新的jQuery Mobile 1.3.0,如果我在控制台上尝试此操作,我会看到警告

$(document).ready(function () {
    alert("test");
});

但如果我尝试这段代码

$(document).on('pageinit', function() {
    alert("test");
});

我没有看到警报,我得到[>#document]对象结果。

知道造成这种情况的原因以及如何显示警报吗?

我正在尝试这个简单的例子,因为在访问页面时使用on('pageshow')似乎没有触发方法。

2 个答案:

答案 0 :(得分:2)

我对您的标题感到困惑,您使用的是pageinit还是pageshow? 因为pageinit非常适合我。

$(document).on('pageinit', function() {
    alert("test");
});

答案 1 :(得分:0)

在pageshow调用中,我们必须使用pageinit方法 以下代码在我们的项目中正常工作。

$('#HomePage').live('pageinit', function() 
                    {
                    }
                );

$('#HomePage').live('pageshow', function() 
                    {
                        alert('pageshow method call');
                    }
                );