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>©Home Page</h4> </div>
<!-- /footer -->
</body>
</html>