【发布时间】:2015-11-26 10:50:46
【问题描述】:
我想在本地存储html5中存储多个动态图像并在页面刷新时检索......
这是我的代码和 jsfiddle
HTML
<ul class="lib">
<li>
<img class='my_image' src='http://wcdn1.dataknet.com/static/resources/icons/set95/5076c9d9.png'>
</li>
<li>
<img class='my_image' src='http://cdn.mysitemyway.com/icons-watermarks/simple-black/raphael/raphael_gear-small/raphael_gear-small_simple-black_128x128.png'>
</li>
</ul>Click the image to make clone and then click save btn to store in local sorage html5 and after that refresh to retreave the images in below box
<div class="block" id="block_test"></div>
<input id="button" type="button" value="save">
CSS
.lib {
border:1px solid #000;
}
.lib li {
display:inline;
}
.lib img {
width:100px;
}
#block_test {
border:1px solid #000;
height:300px;
}
JS
$(".my_image").click(function () {
$(this).clone().addClass('input').removeClass('my_image').appendTo(".block").freetrans({
x: 0,
y: 0
});
});
function setBackground() {
localStorage.input = $(".input").attr('src');
}
function loadBackground() {
if (localStorage.input.length == 0) {
localStorage.input = "empty";
} else {
var img_elem = $('<img id="output">');
img_elem.attr('src', localStorage.input).addClass('input').removeClass('my_image').appendTo(".block").freetrans({
x: 0,
y: 0
});
localStorage.input = $(arr[0]).attr('src');
}
}
$("#button").click(function () {
setBackground();
});
链接到 jsfiddle http://jsfiddle.net/fq58hrh1/14/
提前致谢。我希望我能解决我的问题
【问题讨论】:
-
这里的警报在哪里?
-
因为您正在“警告”DOM 节点,而不是 src 属性。但是等等,哪个警报???
-
@akkii922 你在问题标题中问了
Why alert is showing...哪个警报? -
对不起先生,其实我是新来的..所以我从某个地方复制..我的错误.... :(
-
请解释您的问题 - 什么不起作用?你期待什么结果,你得到了什么。 js控制台有错误码吗?