2013-05-11 64 views
0

我想使用下面包含在函数调用中的代码显示图像。使用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发送到函数,以便我可以显示任何需要的图像(这是函数名称中的'照片'参考)。函数名称如下:

function photoorder(category, reference, photo) 

我试图发送图像URL '../images/autumn/0216.jpg'的函数调用,在接收和格式正确无误。但是当我使用命令src = photo时,图像不显示。例如

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

回答

0

尝试:

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

这工作正常。非常感谢。这是我没有尝试的唯一组合。 – 2013-05-11 10:42:02

0

为此,建议使用jQuery ...

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

的,你应该使用:

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