[英]Transform string into image with jQuery
另一个关于jQuery的问题。
假设我的网页中有图片的网址,并用方括号括起来。
[http://www.example.com/picture.jpg]
我怎么能用jQuery这样转换字符串呢?
[http://www.example.com/picture.jpg]
进入...
<img src="http://www.example.com/picture.jpg" />
?
我会做这样的事情
$("some-selector").each(function(){
$(this).html($(this).html().replace(/\[(http:.*?)\]/gi, function(str, p1){
return "<img src='"+p1+"' />";
}));
});
“某些选择器”应尝试查明这些字符串出现的位置。 如果没有类似的东西...只要放上“ body”,看看会发生什么:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.