2013-02-01 31 views
0

我已經成功在本地存儲中放置了一個變量我現在試圖在下一頁加載時立即顯示該變量,但我不確定如何在頁面轉換後立即執行此腳本。如何在頁面加載後立即從本地存儲顯示變量。 JQuery/JQuery Mobile

我的代碼如下

 <script type="text/javascript"> 
    $("#home").on('pageinit ', function() { 


      //alert('pageinit'); 
      document.getElementById("output").innerHTML="Name: " +localStorage.userName;    

     }); 

    </script> 
    </head><!-- Main Page --> 

    <div id="home" data-role="page" data-title="home"> 
    <div data-role="header"> 
     <h1>Home Page</h1> 
    </div> 
    <!-- /header --> 

    <div data-role="content"> 

    <div id='customer'> Customer Name </div> 
    <p id="output"></p> 
    <a href="index.html" data-role="button">Alarm</a> <a href="index.html" data-role="button">Reports</a> <a href="index.html" data-role="button">Summary</a> </div> 
    <!-- /content --> 

    <div data-role="footer" data-position="fixed" class="ui-bar"> <a href="index.html" data-role="button" >Logout</a> <h4>&copy;Home Page</h4> </div> 


    <!-- /footer --> 

    </body> 
    </html> 

回答

1

可以使用pageChange事件,記錄here

在changePage()請求完成將頁面加載到DOM並完成所有頁面轉換動畫後觸發此事件。

相關問題