jQuery Mobile默认只从外部文档加载第一个data-role="page"
或第一个data-role="dialog"
元素。 <head>
部分甚至被省略。
修复方法是将所有页面放入单个HTML文档或将每个伪页面放置在其自己的HTML文档中。
您可以编写一些代码来手动抓住所有的假网页的外部文件中:
HTML -
<a class="multi-page-link" href="some-external-document.html"></a>
JS -
//when a pseudo-page initializes this code will run
$(document).delegate('.ui-page', 'pageinit', function() {
//find elements tagged with the above class and bind to their `click` events
$(this).find('.multi-page-link').bind('click', function() {
//show the loading spinner
$.mobile.showPageLoadingMsg();
//create AJAX request for href of link
$.ajax({
url : this.href,
dataType : 'html',
success : function (response) {
//on successful response, find all the pseudo-page elements in the external document and append them to the `<BODY>`
var $pseudoPages = $(response).filter('[data-role="page"], [data-role="dialog"]').appendTo('body');
//now hide the loading spinner
$.mobile.hidePageLoadingMsg();
//and navigate to the first pseudo-page that was just added to the DOM
$.mobile.changePage($pseudoPages.eq(0));
},
error : function (a, b, c) { /*Don't for get to handle errors*/ }
});
return false;
});
});
我想有是一个插件,但我不知道它在哪里,或者它是否被支持。
您的'document.pageload'事件处理程序将在每次页面初始化时被绑定。你已经有了'if/then'语句,所以你不会多次添加伪页面,但是你仍然为每个初始化的伪页面运行一次'document.pageload'事件。所以通过第四页,“document.pageload”事件处理程序将运行4次而不是一次。基本上你可以删除外部的委托事件处理程序,因为你的'document.pageload'几乎是一样的东西。好东西,但清理了一下,我一定会投票。 – Jasper 2012-08-08 22:32:18
@Jasper哈哈甚至没有想到这一点。谢谢你收到。 – 2012-08-08 22:44:13
当我运行这个代码时,数据总是有0的计数。我在属性中有几个带'data-role =“page”'的div。有任何想法吗? – ZeroDivide 2012-11-07 21:36:55