Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery javascript将具有图像url的字符串转换为attr_Jquery_Image_Url - Fatal编程技术网

Jquery javascript将具有图像url的字符串转换为attr

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"> ");

我试图弄清楚如何通过添加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"> ");
    $(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', '');