Jquery移动更改页面

siv*_*iva 25 jquery jquery-mobile

我有一个网站的网页布局, http://jquerymobile.com/demos/1.0.1/

现在他们已经提供了使用changePage的规定 <a href="#xxx" data-role="button">Sample</a>

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

$.mobile.changePage("#xxx"); 不适合我

sha*_*bus 51

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

$.mobile.changePage("#page2");
Run Code Online (Sandbox Code Playgroud)

文档: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
});
Run Code Online (Sandbox Code Playgroud)

UPDATE

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

例:

$.mobile.pageContainer.pagecontainer("change", "#page", { options });
Run Code Online (Sandbox Code Playgroud)

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

  • "注意:从jQuery Mobile 1.4.0开始,jQuery.mobile.changePage已被弃用,将在1.5.0中删除.请改用pagecontainer小部件的change()方法." 有没有人有任何使用pagecontainer小部件的例子? (3认同)
  • Siva请发布解决方案或将此标记为答案,如果这实际上是asnwer (2认同)

Pol*_*ris 6

我知道这已经得到了回答,但肯定正确答案为什么它不起作用的是语法不正确?

$ .mobile.changePage需要DOM对象(使用哈希语法在同一HTML文件中显示页面)而不仅仅是字符串.所以给出的例子的正确语法是:

$.mobile.changePage($("#xxx"));
Run Code Online (Sandbox Code Playgroud)

这应该是一种享受!

希望这可以帮助