从您的网址看:index.html#page2
. 您正在尝试导航到一个内部页面(一个已经在 DOM 中的页面)。如果是这种情况,则将 JavaSCript 中的逻辑设置为 on #page2
,当您链接到 时#page2
,将值保存在 JavaScript on可以访问id
的变量中。#page2
就像是:
<ul data-role="listview" id="myList">
<li>
<a href="#page2" data-id="987">This is some fake text... Click for More</a>
</li>
</ul>
<script>
$(document).delegate('#page1', 'pageinit', function () {
//bind to click event for all links in the `#myList` UL
$(this).find('#myList').find('a').bind('click', function () {
//save the ID of this list-item to a global variable so it can be used later
window.myId = $(this).attr('data-id');
});
});
$(document).delegate('#page2', 'pageshow', function () {
//get the ID saved as a global variable
var currentId = window.myId;
//now do logic for second page
});
</script>
这是一个演示:http: //jsfiddle.net/jasper/wFdet/