Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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
Javascript 显示来自查询输出HTML的图像_Javascript_Html_Mysql - Fatal编程技术网

Javascript 显示来自查询输出HTML的图像

Javascript 显示来自查询输出HTML的图像,javascript,html,mysql,Javascript,Html,Mysql,在使用MYSQL的给定数据库中,我存储要显示的图像文件路径。我使用查询检索路径。返回值存储在“var”类型变量中。如何将其作为imgsrc属性的输入来显示图像 例如: var x = "http://www.w3schools.com/jsref/compman.gif"; <img src=x> var x=”http://www.w3schools.com/jsref/compman.gif"; 我无法使用上述内容,因此是否有方法显示图像 提前感谢。您可以使用图像构造函数在J

在使用MYSQL的给定数据库中,我存储要显示的图像文件路径。我使用查询检索路径。返回值存储在“var”类型变量中。如何将其作为
img
src
属性的输入来显示图像

例如:

var x = "http://www.w3schools.com/jsref/compman.gif";
<img src=x>
var x=”http://www.w3schools.com/jsref/compman.gif";
我无法使用上述内容,因此是否有方法显示图像


提前感谢。

您可以使用
图像
构造函数在Javascript中创建新图像

var x=”http://www.w3schools.com/jsref/compman.gif";
var myImage=新图像();
myImage.src=x;
document.body.appendChild(myImage)请尝试以下代码:

var x = "http://www.w3schools.com/jsref/compman.gif";
document.getElementById("YOUR_IMAGR_ID").src = x;

您可以在javascript中动态创建图像标记 Javascript代码

function myFunction() {
    var x = document.createElement("IMG");
    x.setAttribute("src", "http://www.w3schools.com/jsref/compman.gif");
    x.setAttribute("width", "304");
    x.setAttribute("width", "228");
    x.setAttribute("alt", "The Pulpit Rock");
    document.body.appendChild(x);
}
<body>
    <button onclick="myFunction()" >Display Image</button>
</body>
HTML代码

function myFunction() {
    var x = document.createElement("IMG");
    x.setAttribute("src", "http://www.w3schools.com/jsref/compman.gif");
    x.setAttribute("width", "304");
    x.setAttribute("width", "228");
    x.setAttribute("alt", "The Pulpit Rock");
    document.body.appendChild(x);
}
<body>
    <button onclick="myFunction()" >Display Image</button>
</body>

显示图像
请查看

查看以下内容:
函数集(){
document.getElementById('tmp').style.visibility=“visible”;
变量x=”http://www.w3schools.com/jsref/compman.gif";
document.getElementById(“tmp”).src=x;
}


您应该更清楚,如何获取变量?您正在使用或希望使用哪种服务器编程语言?是否希望使用javascript显示图像?为什么“无法使用上述语言”?武断的要求通常意味着学校或学术任务;这并不是禁止的,但在本例中,您需要解释您尝试了什么,以及出现了什么问题。@DavidThomas您是否单击了演示。。它会将你重定向到代码链接,是的,它工作得很好!我不知道.src部分!