2013-03-31 25 views
-1

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

然後我options.js:

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

它應該的innerHTML從[ loading... ]改變值爲mostRecentHat,但它變成未定義的值,並且不會更改innerHTML。

回答

3

你應該傳遞值作爲參數傳遞給html方法。

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