[英]JQuery Mobile - Can't get the parameters from the URL
我有一个动态创建的列表视图,每个列表项都是这样的链接: index.html#ClubPage?id=X
(其中X是int)。
我想在页面加载之前获取ID参数,但似乎该参数消失了。
$("#ClubPage").on("pagebeforeshow", function (event) {
alert( $(this).data("url") );
alert( window.location.href );
alert( window.location.search );
});
使用此代码,第一个警报返回“ ClubPage”,第二个警报返回localhost/#ClubPage
,第三个localhost/#ClubPage
返回空白字符串。
如何获取ID参数及其值? 似乎没有任何效果:-\\
jQuery mobile为单个页面模板处理url。 您将必须以其他方式传递参数。
一个如何做的例子:
<a href="#clubPage" param="3">Some Link</a>
您可以通过多种方式执行此操作,但是我已将id值放在“参数”下的链接中。
在下一节中,我将在单击参数时将其拉出并将其存储在sessionStorage中。 然后重定向到正确的页面。 然后抓取参数“ beforepageshow”。
$('body').on('click','a[href="#clubPage"]',function(e){
e.preventDefault();
var param = $(this).attr('param');
sessionStorage.setItem('clubPage_param', param);
location.href = "index.html#ClubPage";
});
$("#ClubPage").on("pagebeforeshow", function (event) {
var param = sessionStorage.getItem('clubPage_param');
//now you have your item here
});
我敢肯定有多种方法可以执行此操作,您可以将链接保留在href中并进行剪切,然后再重定向到新页面。 或将值存储在javascript变量中。
您还可以制作单个页面,然后以这种方式正常传递参数。 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.