本文介绍了jQuery 移动更改页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为网站上的网页设置了两列布局,http://jquerymobile.com/demos/1.0.1/

I have two column layout for a webpage from the site,http://jquerymobile.com/demos/1.0.1/

现在他们提供了使用更改页面的规定<a href="#xxx" data-role="button">示例</a>

Now they have provided provisions to changePage using<a href="#xxx" data-role="button">Sample</a>

但我的问题是如何使用代码以编程方式更改页面.

But my question is how to programmatically change page using code.

$.mobile.changePage("#xxx"); 对我不起作用

推荐答案

这是一个非常简单的例子:http://jsfiddle.net/shanabus/YjsPD/

Here is a real simple example for you: 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
});

更新

正如 Chase Roberts 在下面的评论中指出的那样,这个 changePage 方法在 1.4 版中已被弃用.这是新的 pagecontainer change 事件的文档.

As Chase Roberts points out in the comments below, this changePage method was deprecated in version 1.4. Here is the documentation for the new pagecontainer change event.

示例:

$.mobile.pageContainer.pagecontainer("change", "#page", { options });

这个问题也解决了这个问题:如何在 jQuery mobile (1.4 beta) 中更改页面?

This was also addressed on this SO question: How to change page in jQuery mobile (1.4 beta)?

这篇关于jQuery 移动更改页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:21