Javascript $(elem).html()=本地存储不工作
My options.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
<!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;
});