我正在尝试在jQuery Mobile中添加changePage事件。
基本上我想加载一个带有“pop”转换的新页面。至关重要的是,我还要更新显示的URL(因此用户可以链接到新页面),我希望页面显示在历史记录中。
目前我正在尝试:
$('#mylink').click(function(){
$.mobile.changePage('/photo.html?p=14545', { transition: "pop"} );
});
<a id="mylink">Click here</a>
但是,这不是更新显示的URL,并且页面似乎也没有正确加载。
有关如何确保URL正确更新和显示的任何建议吗?
谢谢!
更新
请注意,这是外部网址,而不是哈希网址。我正在尝试找到一种转到外部页面的方法,并将URL更新为外部页面的URL。谢谢!
答案 0 :(得分:4)
直播示例:http://jsfiddle.net/r4DyU/1/
HTML:
<div data-role="page" data-theme="c" id="page1">
<div data-role="content">
<p>This is Page 1</p>
<button type="submit" data-theme="a" name="submit" value="submit-value" id="submit-button-1">Open Dialog</button>
</div>
</div>
<div data-role="page" data-theme="a" id="page2">
<div data-role="content">
<p>This is Page 2</p>
<button type="submit" data-theme="e" name="submit" value="submit-value" id="submit-button-2">Close Dialog</button>
</div>
</div>
JS:
$('#submit-button-1').click(function() {
$.mobile.changePage($('#page2'), 'pop');
});
$('#submit-button-2').click(function() {
alert('Going back to Page 1');
$.mobile.changePage($('#page1'), 'pop');
});
// Or try this: Adding the URL
$('#submit-button-1').click(function() {
$.mobile.changePage('/photo.html?p=14545', 'pop');
});
$('#submit-button-2').click(function() {
alert('Going back to Page 1');
$.mobile.changePage('/photo.html?p=14545', 'pop');
});
答案 1 :(得分:2)
$ .mobile.changePage(“#yourpage”,{dataUrl:“#yourpage?x = 1&amp; y = 2”,过渡:“淡出”});
答案 2 :(得分:1)
要更新位置哈希,您需要在changePage选项参数中指定新网址:
$.mobile.changePage('/photo.html?p=14545', {dataUrl: "/photo.html?p=14545", transition: "pop"});