gpt4 book ai didi

javascript - 如何将参数放入 windows.open 中的函数中?

转载 作者:行者123 更新时间:2023-12-02 17:35:38 24 4
gpt4 key购买 nike

我做了一个非常简单的功能,以我调整的特定宽度和高度打开窗口。我的问题是下一个:如何将宽度和高度参数放入 windows.open 中?我只想调用函数并调用参数来获得精确的测量结果。因为我可能会打开 3-4 个不同尺寸的不同窗口...

JavaScript

function ouvrirFenetre(width,height){
window.open('formulaire.php','mywin','left=20,top=20,width='width',height='height'');
}

HTML

<a href="#" onclick="ouvrirFenetre(300,200);">My link</a>

最佳答案

您必须使用 + 符号将字符串与变量连接起来。尝试使用:

function ouvrirFenetre(width,height){
window.open('formulaire.php','mywin','left=20,top=20,width=' + width + ',height=' + height);
}

关于javascript - 如何将参数放入 windows.open 中的函数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22642067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com