Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $(elem).html()=本地存储不工作_Javascript_Jquery - Fatal编程技术网

Javascript $(elem).html()=本地存储不工作

Javascript $(elem).html()=本地存储不工作,javascript,jquery,Javascript,Jquery,My options.html: <!doctype html> <html> <head> <title>Item Notifier v1.0.2</title> <link href="style.css" rel="stylesheet" type="text/css"> <script src="jquery.js"></script> <script

My options.html:

<!doctype html>

<html>
<head>
    <title>Item Notifier v1.0.2</title>
    <link href="style.css" rel="stylesheet" type="text/css">
    <script src="jquery.js"></script>
    <script src="options.js"></script>
</head>
<body>
    <h1>Cowboy's Item Notifyer</h1>
    <label>Last updated hat:<h2 id='itemname'>[ loading... ]</h2></label>
</body>
</html>

它应该将innerHTML从
[loading…]
更改为
mostRecentHat
的值,但它会将该值显示为未定义,并且不会更改innerHTML。

您应该将该值作为参数传递给
html
方法

$(document).ready(function() {
    $('#itemname').html(localStorage.mostRecentHat);
    // document.getElementById('itemname').innerHTML = localStorage.mostRecentHat;
});
$(document).ready(function() {
    $('#itemname').html(localStorage.mostRecentHat);
    // document.getElementById('itemname').innerHTML = localStorage.mostRecentHat;
});