这是记录链接点击然后保存到本地存储然后在div中显示带有链接的图像的正确代码吗?
<script>
var links = [ 'one': 1, 'two': 2, 'three': 3 ];
function saveLink(that){
links[links.length] = that.element.src;
document.getElementById('linkList').innerHTML += that.element.src+"<br>";
localStorage.setItem('links', JSON.stringify(testObject));
}
</script>
<img src="http://domain.com/image.png" onclick="saveLink(this);" />
<div id='linkList'>
<script>
var retrievedObject = localStorage.getItem('links');
console.log('retrievedObject: ', JSON.parse(retrievedObject));
</script></div>