dswy34539 2018-05-16 07:21
浏览 87

onclick链接隐藏img以获得相同的通知想法

I have page php & I have link to download file i need code show img one time OR onclick Link (Download File) Hide img (nof1.gif)

Now I am replacing the image(nof1.gif) in an empty img (empty_img.png) But when reloading the page the images Again

The idea to show the image only once

<a   href="<?php echo base_url($l['admin_file']); ?>" target="_blank" >Download File </a> 



<img id="my_images" src="nof1.gif" style="width:40px;height:30px" 
  onclick="this.src='empty_img.png'; "
  >

or see the code There is an error and I do not know the solution!!!

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

</div>
  • 写回答

1条回答 默认 最新

  • dousi1994 2018-05-16 08:03
    关注

    A simple way is to use cookie

    if (document.cookie.indexOf('image_clicked') > -1) {
        document.getElementById("my_images").src="empty_img.png";
    }
    
    function hideImage() {
        document.getElementById("my_images").src="empty_img.png";
        document.cookie = "image_clicked=true";
    }
    

    Your html :

    <a href="<?php echo base_url($l['admin_file']); ?>" onclick="hideImage()'" target="_blank" >Download File </a>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!