今天分析试了一下,有两个页面index.html和main_wdsp.html
发现在index.html中通过
$.mobile.changePage("main_wdsp.html?userid="+userId,"slidedown", true, true);方法切换页面后,在main_wdsp.html中无法接收到pageinit事件,我把事件写在<head>下方的script中,然后又试了N个事件,也不起作用。
后来遍地找资料,发现对changepage说明是只加载dom中第一个page中的内容。于是我把切换的页面更改了一下
<div data-role="page" id="mainpage">
<script>
$("#mainpage").live("pagecreate",function(){
alert("1");
});
</script>
</div>这样,事件就起作用了。

本文探讨了使用jQuery Mobile框架时遇到的一个问题:从index.html页面通过特定方法切换到main_wdsp.html页面后,目标页面的pageinit事件未能触发。作者通过调整页面结构并在正确的事件监听器中注册回调解决了该问题。
1万+

被折叠的 条评论
为什么被折叠?



