Javascript jQuery Mobile从新html加载第二页
假设我想加载一个新的html文件,其中包含一些jQuery页面,如下所示:Javascript jQuery Mobile从新html加载第二页,javascript,html,jquery-mobile,Javascript,Html,Jquery Mobile,假设我想加载一个新的html文件,其中包含一些jQuery页面,如下所示: $.mobile.changePage("some_page.html"); 如果这个html文件中有两个页面,如何加载第二个页面而不是第一个页面? 我试过了 但它不起作用。 谢谢函数$.mobile.changePage()使用数据角色=“page”获取第一个div,并通过AJAX调用将其加载到dom中。最好的解决方案是将第二页移到html代码的顶部 否则,如果要加载第一页或第二页,可以将它们放在不同的文件中 也许有
$.mobile.changePage("some_page.html");
如果这个html文件中有两个页面,如何加载第二个页面而不是第一个页面?
我试过了
但它不起作用。
谢谢函数
$.mobile.changePage()
使用数据角色=“page”
获取第一个div,并通过AJAX调用将其加载到dom中。最好的解决方案是将第二页移到html代码的顶部
否则,如果要加载第一页或第二页,可以将它们放在不同的文件中
也许有一种方法可以调用第二个页面,但我不知道如何实现这一点。都德尝试将第二个页面元素
数据url
设置为
在目标html页面中。让我知道这对你真的很有用。你可以手动抓取你想要的元素:
//delegate the event binding for some link(s)
$(document).delegate('a.my-link', 'click', function () {
//show the loading spinner
$.mobile.showPageLoadingMsg();
//make the AJAX request for the link's href attribute
$.ajax({
url : this.href,
success : function (serverResponse) {
//get the data-role="page" elements out of the server response
var $elements = $(serverResponse).find('[data-role="page"]');
//you can now access each `data-role="page` element in the `$elements` object
$elements.filter('#page-id').appendTo('body');
//now use changePage to navigate to the newly added page
$.mobile.changePage($('#page-id'), { /*options*/ });
//hide the loading spinner
$.mobile.hidePageLoadingMsg();
},
error : function (jqXHR, textStatus, errorThrown) { /*Don't forget to handler errors*/ }
});
//stop the default behavior of the link, also stop the event from bubbling
return false;
});
但我必须说,按照jQuery Mobile目前的工作方式,您最好将每个
数据角色=“页面”
元素放在一个单独的文档中。ทำแบบนี้ครับ
สำคัญคือให้ใส่ 数据ajax=“false”
คุณก็จะ 换页ได้จากต่างหน้า 用英语回答
//delegate the event binding for some link(s)
$(document).delegate('a.my-link', 'click', function () {
//show the loading spinner
$.mobile.showPageLoadingMsg();
//make the AJAX request for the link's href attribute
$.ajax({
url : this.href,
success : function (serverResponse) {
//get the data-role="page" elements out of the server response
var $elements = $(serverResponse).find('[data-role="page"]');
//you can now access each `data-role="page` element in the `$elements` object
$elements.filter('#page-id').appendTo('body');
//now use changePage to navigate to the newly added page
$.mobile.changePage($('#page-id'), { /*options*/ });
//hide the loading spinner
$.mobile.hidePageLoadingMsg();
},
error : function (jqXHR, textStatus, errorThrown) { /*Don't forget to handler errors*/ }
});
//stop the default behavior of the link, also stop the event from bubbling
return false;
});