pagecontainer更改功能不起作用 [英] pagecontainer change function not working

查看:557
本文介绍了pagecontainer更改功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使pagecontainer更改功能在单击按钮调用的功能内工作.但是由于某种原因,当我在函数外部运行代码时,pagecontainer更改函数无法正常工作.我进行检查以查看用户是否已登录,如果用户未登录,则要进行页面更改/重定向.

I can get the pagecontainer change function to work inside a function that is called with a button click. But for some reason the pagecontainer change function isn't working when I run the code outside of a function. I do a check to see if a user is logged in and then want to do a page change/redirect if they aren't logged in.

 <script>
//works
    function test() {
        $(':mobile-pagecontainer').pagecontainer('change', '#event-list-page');
    }
//doesn't work
    var user = window.localStorage.getItem("user");
    if (user == null){
        alert('not logged in. Should redirect.');
        $(':mobile-pagecontainer').pagecontainer('change', '#event-list-page');
    }
 </script>

此问题的最佳解决方案是什么?我应该只执行javascript重定向吗?还是我需要等待页面完全加载?

What is the best solution for this problem? Should I just do a javascript redirect? Or do I need to wait for the page to load all the way or something?

推荐答案

您应该首先创建$.mobile.pageconatiner,例如:

You should intiate the $.mobile.pageconatiner first, example:

$.mobile.pageContainer.pagecontainer({ defaults: true });

这篇关于pagecontainer更改功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆