1、jQuery 动态创建<img>

$('<img>', {
    src: 'jump/img/f_banner.png',
    alt: 'hello img!',
    title: 'just for test',
    click: function() {
        alert("hello,img!!!");
    }
}).css({
    border: '1px solid red',
    cursor: 'pointer',
    padding: '5px'

}).appendTo('body');

2、当图片路径为空时,什么都不显示

在 <img> 中添加 onerror=this.style.display="none" 

<img onerror=this.style.display="none" src="img/notice_img02.png" />

 

相关文章:

  • 2021-08-02
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2021-06-13
猜你喜欢
  • 2021-07-13
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
相关资源
相似解决方案