Jquery-Mobile:如何重新加载/刷新内部页面

时间:2012-01-05 09:03:57

标签: javascript jquery jquery-mobile

我在容器页面(即page.html)中有2个页面(即page_1和page_2)。在第一页中,如果单击该页面,我只有一个按钮,那么它将导航到第二页。你从第二页回到第一页,然后再次单击导航到第二页的按钮,我想重新加载/刷新页面。我试过,但我没有得到,请任何人帮助我。

这里是代码:

  <div data-role="page" id="page_1" >    

        <div data-role="content" id="contentlogin">         
            <a href="#"  onclick="refresh();" data-role="button" id="login">Navigation</a>                          
        </div>             
    </div> 

   <div data-role="page" id="page_2" >    

        <div data-role="content" id="contentlogin">         
            //Some Form elements are there      
        </div>             
    </div> 

<script type="text/javascript">
 function refresh()
 {                                            
           $.mobile.changePage($("#page_2"), {transition: "pop",reloadPage: true});
 }    
</script>

感谢

1 个答案:

答案 0 :(得分:3)

您可以尝试这样的事情:

JS

$('#page_3').live('pageshow',function(event, ui) {
    // refresh specific element
    $('#refresh').val('');
});

$('#page_2').live('pageshow',function(event, ui) {
    // refresh all elements
    var allInputs = $(':input');
    allInputs.val('');
});

HTML

<div data-role="page" id="page_1" >    
    <div data-role="content" name="contentlogin">         
        <a href="#page_2" data-role="button" id="login">Navigate to page 2</a>   
        <a href="#page_3" data-role="button">Navigate to page 3</a>     
        Yeah Page 1        
    </div>             
</div> 

<div data-role="page" id="page_2" >
    <div data-role="content" name="contentlogin">
        <a href="#page_1" data-role="button">Navigate to page 1</a>     
        <!-- Some Form elements are there -->
        Hello we are on Page 2<br />Refresh All Elements<br /><br />
        <label for="basic1">Text Input 1 (Refresh):</label>
        <input type="text" name="name1" id="basic1" value="" />   
        <label for="refresh1">Text Input 2 (Refresh):</label>
        <input type="text" name="name21" id="refresh1" value="" />
        <br /> Enter in some values, Navigate to Page 1 and back to Page 2    
    </div>             
</div> 

<div data-role="page" id="page_3" >
    <div data-role="content" name="contentlogin">
        <a href="#page_1" data-role="button">Navigate to page 1</a>     
        <!-- Some Form elements are there -->
        Hello we are on Page 3<br />Refresh Specific Elements<br /><br />
        <label for="basic">Text Input 1:</label>
        <input type="text" name="name" id="basic" value="" />   
        <label for="refresh">Text Input 2 (Refresh):</label>
        <input type="text" name="name2" id="refresh" value="" />
        <br /> Enter in some values, Navigate to Page 1 and back to Page 3
    </div>             
</div>