Javascript - 字符串连接

IT技术 javascript
2021-03-01 10:18:11

我有这个功能:

javascript:

function popup(mylink, windowname, w, h)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, "width=w,height=h,scrollbars=yes,toolbar=no" );
return false;
}

html:

<a href="test.html"  onClick="return popup(this, 'Test', '400', '600')">test</a>

我试图在字符串中插入变量wh但没有成功。在 javascript 中执行此操作的正确方法是什么?

2个回答

当然为什么是字符串连接!

"width=" + w + ",height=" + h + ",scrollbars=yes,toolbar=no"
window.open(href, windowname, "width=" + w + ",height=" + h + ",scrollbars=yes,toolbar=no" );