0

使用最新的 jQuery Mobile 1.3.0,如果我在控制台上尝试这个,我会看到警报

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

但是如果我尝试这段代码

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

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

知道是什么原因造成的以及如何显示警报吗?

我正在尝试这个简单的示例,因为 usingon('pageshow')在访问页面时似乎不会触发方法。

4

2 回答 2

2

我被你的标题弄糊涂了,你用的是pageinitorpageshow吗?因为pageinit非常适合我。

$(document).on('pageinit', function() {
    alert("test");
});
于 2013-03-23T20:57:28.547 回答
0

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

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

$('#HomePage').live('pageshow', function() 
                    {
                        alert('pageshow method call');
                    }
                );
于 2013-03-26T09:34:30.127 回答