Javascript jquery mobile url参数未在浏览器中更新,但使用“获取正确的”;数据url“;
我创建了以下示例来展示我的体验 如果我使用按钮page 2a从第1页导航到第2页,URL将如预期的那样为…#page2?id=a 当我单击按钮返回到第1页,然后导航到第2b页时,URL仍将显示“#page2?id=a”,但Javascript jquery mobile url参数未在浏览器中更新,但使用“获取正确的”;数据url“;,javascript,jquery,jquery-mobile,url-parameters,Javascript,Jquery,Jquery Mobile,Url Parameters,我创建了以下示例来展示我的体验 如果我使用按钮page 2a从第1页导航到第2页,URL将如预期的那样为…#page2?id=a 当我单击按钮返回到第1页,然后导航到第2b页时,URL仍将显示“#page2?id=a”,但 代码示例也在JSFIDLE上。问题在于附加了带有ajax导航的url变量。JQM将附加的变量与自己的导航一起使用。根据文档,要么丢失ajax导航,要么丢失变量。使用rel=“external”将其拆分为多个页面也可以解决网站(而不是应用程序)的问题。在stackoverf
代码示例也在JSFIDLE上。问题在于附加了带有ajax导航的url变量。JQM将附加的变量与自己的导航一起使用。根据文档,要么丢失ajax导航,要么丢失变量。使用rel=“external”将其拆分为多个页面也可以解决网站(而不是应用程序)的问题。在stackoverflow问题的帮助下,我使用插件解决了这个问题。以下是我使用此插件的代码:
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
//Added the jqm.page.params plugin
<script src="https://raw.github.com/jblas/jquery-mobile-plugins/35fcf54e2af380aa0e98e9f384572b02f58a1ea1/page-params/jqm.page.params.js"></script>
<script>
$("#page2").live('pageshow', function(e) {
alert($(e.target).attr("data-url")+$.mobile.pageData.id);
//$("#page_text").html("Page 2"+($(e.target).attr("data-url").replace(/.*id=/, "")));
$("#page_text").html("Page 2"+$.mobile.pageData.id);
});
$(document).bind("pagebeforechange", function( event, data ) {
$.mobile.pageData = (data && data.options && data.options.pageData)
? data.options.pageData
: null;
});
</script>
</head>
<body>
<div data-role="page" data-theme="c" id="page1">
<div data-role="content">
<p>Page 1</p>
<a href ="#page2?id=a" data-transition="flip" data-role="button">Page 2a</a>
<a href ="#page2?id=b" data-transition="flip" data-role="button">Page 2b</a>
</div>
</div>
<div data-role="page" data-theme="a" id="page2">
<div data-role="content">
<p id="page_text"></p>
<a href ="#page1" data-transition="flip" data-role="button">Page1</a>
</div>
</div>
</body>
</html>
//添加了jqm.page.params插件
$(“#page2”).live('pageshow',函数(e){
警报($(e.target.attr(“数据url”)+$.mobile.pageData.id);
//$(“#page_text”).html(“第2页”+($(e.target).attr(“数据url”).replace(/.*id=/,”));
$(“#page_text”).html(“第2页”+$.mobile.pageData.id);
});
$(文档).bind(“pagebeforechange”,函数(事件,数据){
$.mobile.pageData=(data&&data.options&&data.options.pageData)
?data.options.pageData
:null;
});
第1页
顺便说一句,我在Firefox、Chrome和Safari中尝试过这一点……在eachI中也有同样的结果,我认为这个库可能已经过时了,我最近创建了一个与jQM 1.4+兼容的新库,如果您仍然需要这类东西的话
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
//Added the jqm.page.params plugin
<script src="https://raw.github.com/jblas/jquery-mobile-plugins/35fcf54e2af380aa0e98e9f384572b02f58a1ea1/page-params/jqm.page.params.js"></script>
<script>
$("#page2").live('pageshow', function(e) {
alert($(e.target).attr("data-url")+$.mobile.pageData.id);
//$("#page_text").html("Page 2"+($(e.target).attr("data-url").replace(/.*id=/, "")));
$("#page_text").html("Page 2"+$.mobile.pageData.id);
});
$(document).bind("pagebeforechange", function( event, data ) {
$.mobile.pageData = (data && data.options && data.options.pageData)
? data.options.pageData
: null;
});
</script>
</head>
<body>
<div data-role="page" data-theme="c" id="page1">
<div data-role="content">
<p>Page 1</p>
<a href ="#page2?id=a" data-transition="flip" data-role="button">Page 2a</a>
<a href ="#page2?id=b" data-transition="flip" data-role="button">Page 2b</a>
</div>
</div>
<div data-role="page" data-theme="a" id="page2">
<div data-role="content">
<p id="page_text"></p>
<a href ="#page1" data-transition="flip" data-role="button">Page1</a>
</div>
</div>
</body>
</html>