此代码替换图像并保留cookie
有错吗?我不知道解决方案。
<html>
<button onclick="hideImage()"> Remove img </button>
<img id="my_images" src="http://karachiairport.com.pk/images/data-section/airline/24-11.png">
<script>
document.addEventListener('DOMContentLoaded', function() {
// If cookie exist
if (document.cookie.indexOf('image_clicked') > -1) {
document.getElementById("my_images").src="http://www.1dmag.com/all_asset/img/no-image.png";
}
function hideImage() {
document.getElementById("my_images").src="http://www.1dmag.com/all_asset/img/no-image.png";
document.cookie = "image_clicked=true";
}
});
</script>
&#13;
答案 0 :(得分:0)
请试一试。
现在&#39; hideImage未定义&#39;错误已解决。
<html>
<button onclick="hideImage()"> Remove img </button>
<img id="my_images" src="http://karachiairport.com.pk/images/data-section/airline/24-11.png">
<script>
document.addEventListener('DOMContentLoaded', function() {
// If cookie exist
if (document.cookie.indexOf('image_clicked') > -1) {
document.getElementById("my_images").src="http://www.1dmag.com/all_asset/img/no-image.png";
}
});
function hideImage() {
document.getElementById("my_images").src="http://www.1dmag.com/all_asset/img/no-image.png";
document.cookie = "image_clicked=true";
}
</script>
&#13;