Jquery javascript将具有图像url的字符串转换为attr
我试图弄清楚如何通过添加img attr将用户输入的包含图像url的字符串转换为图像显示 以下是我一直在玩的游戏:Jquery javascript将具有图像url的字符串转换为attr,jquery,image,url,Jquery,Image,Url,我试图弄清楚如何通过添加img attr将用户输入的包含图像url的字符串转换为图像显示 以下是我一直在玩的游戏: $(".message_content").each(function() { var text = $(this).text(); text = text.replace("http://www.example.org/myimage.jpg", "<img src="http://www.example.org/myimage.jpg"> ");
$(".message_content").each(function() {
var text = $(this).text();
text = text.replace("http://www.example.org/myimage.jpg", "<img src="http://www.example.org/myimage.jpg"> ");
$(this).text(text);
});
$(“.message\u content”)。每个(函数(){
var text=$(this.text();
text=text.replace(“http://www.example.org/myimage.jpg", " ");
$(此).text(文本);
});
虽然这不起作用,但有人尝试过类似的方法吗?跳过“
text=text.replace(“http://www.example.org/myimage.jpg",
" ");
更一般的:
var userinput = "http://www.example.org/myimage.jpg";
text = text.replace(userinput, "<img src=\"" + userinput + "\">");
var userinput=”http://www.example.org/myimage.jpg";
text=text.replace(userinput,“”);
退出“
text=text.replace(“http://www.example.org/myimage.jpg",
" ");
更一般的:
var userinput = "http://www.example.org/myimage.jpg";
text = text.replace(userinput, "<img src=\"" + userinput + "\">");
var userinput=”http://www.example.org/myimage.jpg";
text=text.replace(userinput,“”);
退出“
text=text.replace(“http://www.example.org/myimage.jpg",
" ");
更一般的:
var userinput = "http://www.example.org/myimage.jpg";
text = text.replace(userinput, "<img src=\"" + userinput + "\">");
var userinput=”http://www.example.org/myimage.jpg";
text=text.replace(userinput,“”);
退出“
text=text.replace(“http://www.example.org/myimage.jpg",
" ");
更一般的:
var userinput = "http://www.example.org/myimage.jpg";
text = text.replace(userinput, "<img src=\"" + userinput + "\">");
var userinput=”http://www.example.org/myimage.jpg";
text=text.replace(userinput,“”);
用户输入的字符串是什么?用户输入的字符串是什么?用户输入的字符串是什么?用户输入的字符串是什么?是或在JS中使用单引号:text=text。替换('http://www.example.org/myimage.jpg', '');
yes或在JS中使用单引号:text=text.replace('http://www.example.org/myimage.jpg', '');
yes或在JS中使用单引号:text=text.replace('http://www.example.org/myimage.jpg', '');
yes或在JS中使用单引号:text=text.replace('http://www.example.org/myimage.jpg', '');代码>