工作中遇到要实现点击图片查看的功能,从网上找了一段js代码,可以用。

<img src="/pic/${pictureCertificate}" alt="凭证" width="100" height="100" id = "pictureCertificate" onerror="hidepic()">

function AddImgClickEvent()
    {

        var objs = document.getElementsByTagName("img");
        for(var i=0;i<objs.length;i++)
        {
            objs[i].onclick=function()
            {
                window.open(this.src);
            }
            objs[i].style.cursor = "pointer";
        }
    }
    AddImgClickEvent();

效果图:
JS实现点击图片,在浏览器中查看。

JS实现点击图片,在浏览器中查看。

小结

记录一下工作时遇到的问题,方便下次使用!

相关文章:

  • 2021-07-12
  • 2022-12-23
  • 2021-11-17
  • 2021-11-15
  • 2021-11-29
  • 2021-07-31
  • 2022-12-23
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2021-05-21
  • 2021-12-05
  • 2022-01-25
  • 2021-04-18
  • 2021-04-19
  • 2022-01-03
相关资源
相似解决方案