我有两个页面,使用jQuery Mobile的p1.html
和p2.html
。p1.html
中有一些链接,所有链接都导航到p2.html
,但有一点区别。
我想将int
参数传递给p2.html
javascript(例如,链接号),因此p2.html
中的javascript代码对基于int
参数的自身进行很少的更改(在过渡开始之前)。
我想使用Ajax导航功能和jQuery Mobile的Transitions,也不想使用页面锚点(p2.html#6
)。
如何将该参数发送到p2.html
?
最佳答案
您可以使用cookie来保存相关信息吗?
获取cookie jquery plugin。
p1.html
<a href="p2.html" data-p2data="1">Link 1</a>
<a href="p2.html" data-p2data="2">Link 2</a>
<script type="text/javascript">
$(document).ready(function(){
$('a[data-p2data]').click(function(){
$.cookie('p2data', $(this).data('p2data'));
}
}
</script>
p2.html
<script type="text/javascript">
var p2data = $.cookie('p2data');
// .. process the page based on the value in p2data.
</script>