我使用本地存储将信息从一个页面传递到另一页面,现在我必须将此信息分配给 html 元素,我将如何做到这一点?
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$( document ).ready(function() {
var globalarray = [];
var arrLinks =[];
arrLinks = JSON.parse(window.localStorage.getItem("globalarray"));
$(#booking)// How to assign arrLinks here
});
</script>
</head>
<body>
<p id="booking">Not loaded yet.</p>
</body>
</html>
最佳答案
需要调用jquery的html函数
$('#booking').html(arrLinks);
您还需要将其作为 JSON 字符串而不是 JSON 传递。
所以不要解析 JSON。
arrLinks = window.localStorage.getItem("globalarray");
关于javascript - 如何为html元素分配本地存储值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28471019/