开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜