gpt4 book ai didi

javascript - For 循环打开 url

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:35:09 25 4
gpt4 key购买 nike

我正在使用 for 循环打开多个 url,但它只打开数组中的第一个项目。我尝试过使用 for ( i in array) 但它得出了相同的结果。

    <HTML>

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

function launchproducts (form) {

var input_from_user = form.inputbox.value;

var product_numbers;

product_numbers = input_from_user.split(";",100000);


for ( var i = 0; i < product_numbers.length; i++) {
launch_code = "http://www.youtube.com/results?search_query=" + product_numbers[i];

window.open(launch_code, '_blank');

}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="" METHOD="GET">Enter product numbers: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" onClick="launchproducts(this.form)">
</FORM>
</BODY>
</HTML>

最佳答案

试试这个:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function launchproducts (form) {
var input_from_user = form.inputbox.value;
var product_numbers;
product_numbers = input_from_user.split(";",100000);
for ( var i = 0; i < product_numbers.length; i++) {
var launch_code = "http://www.youtube.com/results?search_query=" + product_numbers[i];
var go = confirm("Launch next ? (" + product_numbers[i] + ")");
if (go) {
window.open(launch_code, '_blank');
}
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="" METHOD="GET">Enter product numbers: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" onClick="launchproducts(this.form)">
</FORM>
</BODY>
</HTML>

关于javascript - For 循环打开 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14547783/

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