我有兩個欄佈局從網站的網頁, http://jquerymobile.com/demos/1.0.1/jQuery Mobile的變化
現在他們已經使用 <a href="#xxx" data-role="button">Sample</a>
提供規定changePage但我的問題是如何使用的代碼編程方式更改頁。
$.mobile.changePage("#xxx");
不是爲我工作
我有兩個欄佈局從網站的網頁, http://jquerymobile.com/demos/1.0.1/jQuery Mobile的變化
現在他們已經使用 <a href="#xxx" data-role="button">Sample</a>
提供規定changePage但我的問題是如何使用的代碼編程方式更改頁。
$.mobile.changePage("#xxx");
不是爲我工作
這裏是你一個真實簡單的例子:http://jsfiddle.net/shanabus/YjsPD/
$.mobile.changePage("#page2");
文檔:http://api.jquerymobile.com/jQuery.mobile.changePage/
其他例子:
//transition to the "about us" page with a slideup transition
$.mobile.changePage("about/us.html", { transition: "slideup"});
//transition to the "search results" page, using data from a form with an ID of "search""
$.mobile.changePage("searchresults.php", {
type: "post",
data: $("form#search").serialize()
});
//transition to the "confirm" page with a "pop" transition without tracking it in history
$.mobile.changePage("../alerts/confirm.html", {
transition: "pop",
reverse: false,
changeHash: false
});
UPDATE
正如Chase Roberts在下面的評論中指出的,這個changePage
方法在版本1.4中已被棄用。以下是新的pagecontainer change事件的文檔。
例子:
$.mobile.pageContainer.pagecontainer("change", "#page", { options });
這也是解決這個問題的SO:How to change page in jQuery mobile (1.4 beta)?
我知道這已經回答了,但肯定是正確的答案,爲什麼它不工作是語法不正確?
$ .mobile.changePage需要DOM對象(用於在使用散列語法的同一個HTML文件中顯示頁面),而不僅僅是一個字符串。所以給出的例子的正確語法是:
$.mobile.changePage($("#xxx"));
這應該是一種享受!
希望這有助於
不,這是正確的語法$.mobile.changePage("#page2");
或$.mobile.changePage("about/us.html");
請參閱API
請閱讀上述答案。 – siva 2013-02-08 17:41:47
$.mobile.changePage($("#page2"));
是DIV是可見頁面之間切換的正確方法。
如果使用
$.mobile.changePage("#page2");
的DOM將重新加載,並且任何ondocumentready事件將被觸發。
+1 MM - 根據我的經驗,如果您要從文件加載HTML頁面,那麼如果回調到父級,則該文件中的任何ChangePage調用都需要使用完整的DOM對象,而不僅僅是標籤。 – 2013-09-24 02:39:33
您首先檢查div塊的開始和結束標記bcoz,如果某些標記丟失,頁面轉換是不可能的。 之後,使用下面的代碼
$.mobile.changePage("#page2");
function signin() {
alert('singin button has been clicked');
$.ajax({
type: 'POST',
url: 'http://localhost:8080/json/login',
dataType: "json",
headers: {'Authorization':'Basic '+ btoa('abc' + ':' + '12345')},
contentType: 'application/json',
data:loginFormToJSON(),
success: function(data, textStatus, jqXHR)
{
if(data.token !="ErrorID-11000"){
alert('login successfully');
//document.location.href = "accountinfo.html";
//document.getElementById("loginBtn").replace="accountinfo.html";
$.mobile.changePage("accountinfo.html");
}
else{
alert('userid password did not match');
}
},
error: function(jqXHR, textStatus, errorThrown){
alert('login error:'+errorThrown + textStatus);
}
});
}
從上面的代碼,我在登錄頁面,將帳戶頁面登錄成功,這正與jQuery Mobile的1.4。
希望有所幫助。
感謝@shanabus當簡單頁面被使用時,這個答案正在工作。但是我使用左側邊欄這是一個菜單,右側窗格是內容窗格。基於側窗格中的變化,內容頁面必須被加載。因爲我想有動態的內容,我需要頁面過渡編程。 – siva 2012-03-16 19:36:57
如果你看看Docs頁面是如何做的話,它會重新加載整個頁面,而不僅僅是內容窗格。 – shanabus 2012-03-16 20:45:32
Thanks @shanabus有什麼方法可以單獨重新加載內容窗格? – siva 2012-03-17 05:36:10