【问题标题】:Argument passed to JS method inefficent传递给 JS 方法的参数无效
【发布时间】:2013-02-28 23:06:24
【问题描述】:

谁能告诉我这个sn-p有什么问题?

<!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 时,方法 .open 中与窗口大小相关的两个参数没有结果——该方法坚持一些默认值。

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

【问题讨论】:

标签: javascript


【解决方案1】:

您需要实际替换变量的值。

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

【讨论】:

    【解决方案2】:

    参数以正确的方式传递,但 used 的传递方式不正确。

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

    您在引号中有myWidthmyHeight,它们不会告诉javascript 这些是变量。这两个必须是外部引号。

    像这样:

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

    【讨论】:

      猜你喜欢
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 2018-01-16
      • 2015-06-30
      相关资源
      最近更新 更多