2012-01-27 50 views
1

我试图使用在文档jQuery Mobile的,我怎么手动更改页面上的“pagebeforeload”事件

$(document).bind("pagebeforeload", function(event, data){ 

// Let the framework know we're going to handle the load. 

event.preventDefault(); 

// ... load the document then insert it into the DOM ... 
// at some point, either in this callback, or through 
// some other async means, call resolve, passing in 
// the following args, plus a jQuery collection object 
// containing the DOM element for the page. 

data.deferred.resolve(data.absUrl, data.options, page); 

}); 

定义的方法来重定向页面,但我不知道究竟是什么PARAMS解决问题我无法在任何地方找到文档,页面参数究竟是什么?

+1

您应该在pagebeforechange上重定向 – frequent 2013-08-14 07:09:42

回答

0

我有这个相同的问题,我最终做的是创建一个隐藏的按钮,然后触发该按钮上的单击事件。我知道这可能不是正确的做法,但我认为我会提供解决方案/破解。如果其他人有更好的东西,我真的很想听到它。

JS

$("#login-btn").click(); 

HTML

<div style='display:none;'><a href="#login" id='login-btn' data-role="button" data-rel="dialog" >HIDDEN</a></div> 
0

该文档是指page对象松散referred to here

所以,我想你会想是这样的:

var page = $("#page2"); 

这可以回答你的问题,但可能不会做很多工作来解决你的问题。有几种方法可以解决这个问题,但这里有一个如何重定向到pagechange上的特定页面的示例:http://jsfiddle.net/BD9ax/

希望这有助于解决您的问题。

0
// the following args, plus a jQuery collection object 
// containing the DOM element for the page. 

他们使用page来表示额外的参数。例如

var $page = $('<div data-role="page" data-dom-cache="true">' 
    + 'your content' 
    + '</div>'); 
data.options.pageContainer.append($page); 
data.deferred.resolve(data.absUrl, data.options, $page); 

这是与jQuery Mobile 1.3。