Transform string into image with jQuery
Another jQuery question for you guys.
Say I have a url of an image in my web page surrounded by square brac开发者_运维百科kets.
[http://www.example.com/picture.jpg]
How could I, with jQuery transform that string like so...
[http://www.example.com/picture.jpg]
into...
<img src="http://www.example.com/picture.jpg" />
?
I'd do something like this
$("some-selector").each(function(){
$(this).html($(this).html().replace(/\[(http:.*?)\]/gi, function(str, p1){
return "<img src='"+p1+"' />";
}));
});
"some-selector" should try to pinpoint where these string occur. If there is nothing like it... just put "body" and see what happens :)
精彩评论