如何在Jquery Mobile中取消显示一个页面而显示另一个页面?

如何在Jquery Mobile中取消显示一个页面而显示另一个页面?,jquery,jquery-mobile,Jquery,Jquery Mobile,我正在用Jquery mobile构建一个移动应用程序,根据一些规则,我需要取消显示一个页面,改为显示另一个页面 我有以下代码: $('#login').live("pagebeforeshow", function() { /*-> Here i have some code where i decide if i continue loading the page or load(changepage) another page instead.*/ }); 谢谢你

我正在用Jquery mobile构建一个移动应用程序,根据一些规则,我需要取消显示一个页面,改为显示另一个页面

我有以下代码:

$('#login').live("pagebeforeshow", function() {
    /*-> Here i have some code where i decide 
    if i continue loading the page or load(changepage) another page instead.*/
});
谢谢你的建议帮助我。 我最好使用“pagebeforecreate”而不是“pagebeforeshow”,或者您有什么建议吗?

.live()
不推荐使用,请使用
.on()
代替:

$(document).on("pagebeforecreate", "#login", function(event){ 
   if(condition){
      event.preventDefault();
      event.stopPropagation();
      $.mobile.changePage("login.htm");
   }
});

当你甚至不打算使用它时,为什么要创建一个页面-/因为我需要检查用户是否已经登录,如果没有,那么我需要继续显示“#login”页面(因为这是第一个页面)。如果用户已登录,则我需要显示#面板页面。