[英]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.