Jquery移动刷新索引页面上的后退按钮

时间:2013-01-07 13:57:04

标签: jquery-mobile refresh

我有一个动态加载json对象的索引页面。如果我去第二页然后我尝试使用后退按钮返回索引我想重新加载索引页面,所以它重新加载可以更改的json对象。这是我的index.html页码:

<html> 
<head> 
    <title>Test</title> 
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" /> 
    <link rel="stylesheet" href="jquery.mobile-1.2.0.min.css" />
    <script src="js/jquery-1.8.2.min.js"></script>      
    <script src="jquery.mobile-1.2.0.min.js"></script>
    <script type="text/javascript" src="cordova-2.2.0.js"></script>
</head>

<body>
<div data-role="page" id="pagina">
    <div data-role="header" data-position="fixed" data-theme="d">
        <h1 style="font-size:14px">test</h1>
    </div><!-- /header -->

    <div data-role="content" id="content">  
        <ul data-role="listview" id="ul_id" data-theme="b" data-inset="true">
        </ul>
    </div><!-- /content -->
</div>
</body>
</html>
<script>
    $.getJSON('http://www.test.com/test.php', function(data) {
    var items = [];
    $.each(data, function(key, val) {
    $('#ul_id').append($('<li><a href="' + val +'.cfm" id="'+ val +'"><h3>' + key + '</h3></a></li>'));
    });
    $('#ul_id').listview('refresh');
    });
</script>

我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以像这样使用pagebeforeshowpageshow event

$(document).on("pagebeforeshow", "#pagina", function() {
    //put your code here to manipulate the content
});