【发布时间】:2014-01-03 22:24:17
【问题描述】:
我能够成功存储日志值,但在同一域的另一个页面中显示日志值时遇到问题。我通过localStorage 将记录的值存储在first.html 中。我的代码是:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
//code of localStorage goes here
})
</script>
</head>
<body>
<form id="logForm" method="post">
<input type="text" name="project" value="Project Name">
<input type="submit" value="Log Time">
</form>
<a href="otherpage.html">
This is a link to otherpage.html
</a>
</body>
</html>
我想在otherpage.html 中显示记录的值。我在otherpage.html 中的代码是:
<!DOCTYPE html>
<html>
<body>
<p>This page will show the logged values</p>
<ul id="theLog"></ul>
<button type="button" id="clearLog">Clear Log</button>
</body>
</html>
不幸的是,当我尝试显示 ul 时,otherpage.html 没有显示任何内容。谁能告诉我为什么它没有显示任何内容或建议一些替代方法在otherpage.html 中显示它。附言我不想在同一页面中显示它。
【问题讨论】:
-
但是您没有在 otherpage.html 上调用
localStorage...。您希望在这里发生什么? -
如何在
otherpage.html上拨打localStorage? -
var myHtml = localStorage['key'] -
需要在otherpage.html中包含相应的javascript,但可以跨页面访问
localStorage。
标签: jquery html forms local-storage