传递给JS方法的参数inefficent

问题描述:

有人会告诉我这段代码有什么问题吗?传递给JS方法的参数inefficent

<!DOCTYPE html> 
<html> 
<head> 
<script> 
function anotherWindow(msg, myWidth, myHeight) 
{ 
theWindow=window.open('','','width=myWidth,height=myHeight'); 
theWindow.document.write(msg); 
theWindow.focus(); 
} 
</script> 
</head> 
<body> 

<input type="button" value="One more window" onclick="anotherWindow('Here is the window',200,100)" /> 

</body> 
</html> 

虽然第一个参数(MSG)被成功传递给方法.WRITE,在方法中的有关窗口大小两个参数。开带来任何结果-the方法棍棒一些默认值。

我对变量传递的理解有什么问题?

+2

检查这个答案:http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice – elclanrs 2013-03-13 06:01:29

参数正在通过正确的方式,但它们不是正确的方式used

theWindow=window.open('','','width=myWidth,height=myHeight'); 

你有引号,不会告诉JavaScript的,那些是变量myWidthmyHeight。这两个必须在引号之外。

像这样:

theWindow=window.open('','','width='+myWidth+',height='+myHeight); 
+0

我没有得到这一点。谢谢大家。 – 2013-03-13 12:14:26

实际上你需要在变量的值替代。

theWindow=window.open('','','width='+myWidth+',height='+myHeight); 
+0

我确实明白了。谢谢大家。 – 2013-03-13 12:14:44