我正在尝试将一些参数传递给在jQuery手机中生成的页面id。
该站点由带有链接的列表视图组成,每个列表视图中都有散列编码,如下所示:
<li><a href="#pronostico?region=12&ciudad=0">Puerto Natales</a></li>
我绑定了pagebeforechange
来捕获URL中的散列,做参数检测,并根据传递的参数数量采取行动。
现在,对于cookies,我一直在尝试这样做:
$(document).one("pageinit", function(event, data) {
if (location.hash.search(/^(#ciudades|#pronostico)/) === -1) {
if ($.cookie("recordar")) {
$.mobile.changePage($("#pronostico"), {
data: "region=" + $.cookie("region") + "&ciudad=" + $.cookie("ciudad")
});
}
}
});
但它只是将我传递给#pronostico
-id,散列中没有参数。结果,我得到了一个没有应该显示的信息的页面。
提前谢谢。
发布于 2014-09-29 12:16:15
不过,该插件不支持书签。如果你添加了一个页面更改处理程序,你可以通过在jQM完成后将参数放回url来解决这个问题:
// list of inner pages where you want to support params AND bookmarking
// maybe better to use a CSS class name to mark them
var $paramPages;
$(document).ready(function() {
$paramPages = $('#book, #order');
});
// put the params back into the location once jQM is done
//
$( document ).bind( "pagechange", function( e, data ) {
if (data.toPage.is($paramPages) && data.absUrl) {
window.location.replace(data.absUrl);
}
});
发布于 2016-01-04 03:22:47
在本例中,实现页面之间传递URL参数的一种方法是使用散列处理方法,该方法来自jQuery Mobile文档:http://demos.jquerymobile.com/1.4.1/navigation-hash-processing/
此解决方案似乎很理想,因为与其他解决方案不同的是,它会在页面之间更改时更新浏览器地址栏中的URL,以包括URL参数。这种方法还不需要使用任何插件,如'jqm.page.params‘。
https://stackoverflow.com/questions/8238762
复制相似问题