2013-03-05 83 views
0

在這裏工作是示例代碼(test.html中),jQuery Mobile的 - changePage不pageinit

<!DOCTYPE html> 
<html> 
<head> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css"/> 
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> 
</head> 
<body> 

<div data-role="page" id="page1"> 
<div data-role="content" id="content">Page 1</div> 
</div> 

<div data-role="page" id="page2"> 
<div data-role="content" id="content" >Page 2</div> 
</div> 

<script> 
$('#page2').live('pageinit',function(evt) { 
    $.mobile.changePage($('#page1'),{allowSamePageTransition:true}) 
}); 
</script> 

</body> 
</html> 

當我嘗試訪問./test.html#page2同時使用Firefox和Chrome,它是預計將更改爲page1。但它並未總是成功更改爲page1。有時候,它在頁面2中仍然保持不變。任何人知道爲什麼?

謝謝!

回答

0

爲什麼不試試如下

$('#page2').on('pageshow',function(evt) { 
    $.mobile.changePage($('test.html#page1'),{allowSamePageTransition:true}) 
}); 

和另一個忠告憑我的經驗是,在導航錯誤的緩行嵌套JQM頁面的結果。作爲一個拇指規則,我總是爲我的JQM HTML頁面分開頁面。

相關問題