Inputting a default image in case the src attribute of an html

后端 未结 22 2456
渐次进展
渐次进展 2020-11-22 16:02

Is there any way to render a default image in an HTML tag, in case the src attribute is invalid (using only HTML)? If not, what would

22条回答
  •  误落风尘
    2020-11-22 16:22

    You asked for an HTML only solution...

     
    
    
    
    
      Object Test
      
    
    
    
    
      

    Stack Overflow logo and icons and such

    Since the first image doesn't exist, the fallback (the sprites used on this web site*) will display. And if you're using a really old browser that doesn't support object, it will ignore that tag and use the img tag. See caniuse website for compatibility. This element is widely supported by all browsers from IE6+.

    * Unless the URL for the image changed (again), in which case you'll probably see the alt text.

提交回复
热议问题