<img>总结: 动态创建等问题

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

猜你喜欢

转载自www.cnblogs.com/miny-simp/p/9554322.html
IMG