[英]Transform string into image with jQuery
Another jQuery question for you guys. 另一个关于jQuery的问题。
Say I have a url of an image in my web page surrounded by square brackets. 假设我的网页中有图片的网址,并用方括号括起来。
[http://www.example.com/picture.jpg]
How could I, with jQuery transform that string like so... 我怎么能用jQuery这样转换字符串呢?
[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 :)
如果没有类似的东西...只要放上“ body”,看看会发生什么:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.