2017-04-05 100 views
1

我的代碼是這樣的:如何更改jQuery Mobile中的頁面?

<div data-role="page" id="LoginPage"> 

    <div data-role="header"> 

    </div> 

    <div data-role="main" class="ui-content"> 
    <input type="button" value="התחבר" onclick="checkDetails()" /> 
    </div> 

    <div data-role="footer"> 

    </div> 
</div> 

現在,通過功能checkDetail()我需要移動到anthor頁面(如下圖)

<div data-role="page" id="HomePage"> 

    <div data-role="header"> 
     <h3>asd</h3> 
    </div> 

    <div data-role="content" class="ui-content"> 

    </div> 

    <div data-role="footer"> 
     <ul> 
      <li><a>a</a></li> 
      <li><a>as</a></li> 
      <li><a>asd</a></li> 
     </ul> 
    </div> 
</div> 

的問題是,當我移動到它,我達到主頁,但它顯示爲一個正常的HTML頁面而不是jQuery的手機。 順便說一句,LoginPage顯示爲jQueryMobile,但HomePage不是。

這就是我的移動,

$('#LoginPage').hide(function() { 
    $('#HomePage').show(); 
}); 

回答

1

你不應該使用jQuery核心庫的$.show()$.hide()方法頁面導航。 jQuery Mobile中的頁面導航通過Pagecontainer Widget進行處理 - 具體使用change方法。

在你的榜樣,你會做以下幾點:

var homePage = $("#HomePage"); 
$.mobile.pageContainer.pagecontainer("change",homePage,{}); 
+0

我在一些視頻觀看,作品簡單地說, 不是像你說的,順便我打開網頁,但不是設計的手機 –

+0

我無法理解。如果你說你看到一個告訴你使用'.show()'和'.hide()'來打開jQuery Mobile頁面的視頻,那麼這個視頻是錯誤的。您需要使用Pagecontainer小部件。請查看Omar鏈接的重複問題以獲得相同的答案。 –