使用Javascript调用函数时图像显示错误

时间:2013-05-11 10:27:37

标签: javascript

我想使用下面的代码显示图像,该代码包含在函数调用中。

myWindow.document.write("<center><img border='2' src='../images/autumn/0216.jpg' width='120' height='90' /></center>");

当您明确设置src详细信息时,这可以正常工作,例如src = '../images/autumn/0216.jpg',图片显示正确。我需要做的是将图像的url发送到函数,以便我可以显示所需的任何图像(这是函数名称中的'photo'引用)。函数名称如下:

function photoorder(category, reference, photo)

我尝试将图片网址'../images/autumn/0216.jpg'发送到函数调用,它已被正确接收和格式化。但是当我使用命令src = photo时,不会显示图像。 e.g。

myWindow.document.write("<center><img border='2' src='photo' width='120' height='90' /></center>"); 

myWindow.document.write("<center><img border='2' src=photo width='120' height='90' /></center>"); 

2 个答案:

答案 0 :(得分:0)

尝试:

myWindow.document.write("<center><img border='2' src='" + photo + "' width='120' height='90' /></center>");

答案 1 :(得分:0)

为此目的建议使用jQuery ...

但是在你的功能photoorder(...)照片是一个像“../images/autumn/0216.jpg”这样的参数?

你应该使用:

myWindow.document.write("<center><img border='2' src='" + photo + "' width='120' height='90' /></center>");