[英]Save event onclick js
我有这个代码
<script>
var content = document.getElementById('float_content_right');
var hide = document.getElementById('hide_float_right');
function hide_float_right() {
if (content.style.display == "none") {
content.style.display = "block";
hide.innerHTML = '<a href="javascript:hide_float_right()">Close [X]</a>';
} else {
content.style.display = "none";
hide.innerHTML = '<a href="javascript:hide_float_right()">Open...</a>';
}
}
var images = new Array();
images[0] = "<a href='http://phuongnuochoa.com' target='_blank'><img src='http://thegioidoco.net/gif/1.gif'></a>";
images[1] = "<a href='http://quattran.com' target='_blank'><img src='http://thegioidoco.net/gif/2.gif'></a>";
images[2] = "<a href='http://dogoducthien.vn' target='_blank'><img src='http://thegioidoco.net/gif/3.gif'></a>";
$(images[Math.floor(Math.random() * images.length)]).appendTo('#float_content_right');
setInterval(function () {
$('#float_content_right').empty();
$(images[Math.floor(Math.random() * images.length)]).appendTo('#float_content_right');
}, 5000);
</script>
现在我想要,当我按下“关闭”按钮时,图像被隐藏,然后再次按F5键,图像仍被隐藏。 而且,如果我不按“关闭”按钮,则在我按F5键时,图像仍然存在。
请帮助我,这是我的锻炼!
谢谢。
在代码中使用会话存储。 这样 。
单击关闭按钮后,在会话存储中设置一个密钥。
// Save data to sessionStorage
sessionStorage.setItem('imageVisible', '1');
在F5或页面加载函数调用中,通常$(document).ready(function(){})
可以进行检查。
// Get saved data from sessionStorage
var data = sessionStorage.getItem('imageVisible');
if(data == 1)
{
//show the div containing the image.
}
else
{
//hide the div containing the image.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.