开发者

How to put a display a default image if no src specified?

开发者 https://www.devze.com 2023-03-26 23:55 出处:网络
I have HTML from a database that sometimes give no src values like this: <img class=\"some-image\" src=\"\"开发者_StackOverflow>

I have HTML from a database that sometimes give no src values like this:

<img class="some-image" src=""开发者_StackOverflow>

How do I supply it with an image if there is no src value like above?


You can test the src attribute to see if it's empty:

$('img[src=""]').attr("src", "default.jpg");


$('img[src=""]').attr('src', 'urltoimage');


You can define it on the css class as background for the tag and overwrite it with the src tag where available. Are you meaning this?

0

精彩评论

暂无评论...
验证码 换一张
取 消