$(elem).html()= localStorage不起作用

时间:2013-03-31 04:00:06

标签: javascript jquery

我的选项:

<!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>

然后我的options.js:

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

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

1 个答案:

答案 0 :(得分:3)

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

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