读取列表框(dpAddress),其中列出了多个IP地址。我选择其中几个,并希望使用另一种形式(loginForm)提供的username-password-domain向每个选定的IP发送请求。如果我在列表中选择了2个IP地址,我已经验证了循环工作了2次。但它只打开了一个新标签。
我希望在表单提交后在浏览器的同一窗口中打开多个选项卡。我怎么能这样做?
function formSubmit1()
{
len = document.dpForm.dpAddress.length
i = 0
for (i = 0; i < len; i++) {
if (document.dpForm.dpAddress[i].selected) {
alert(document.dpForm.dpAddress[i].selected)
var f = document.createElement("form");
f.setAttribute('method',"post");
var user = document.createElement("input"); //input element, text
user.setAttribute('type',"text");
user.setAttribute('name',"user");
user.setAttribute('value',document.loginForm.user.value);
var pass = document.createElement("input"); //input element, Submit button
pass.setAttribute('type',"text");
pass.setAttribute('name',"pass");
pass.setAttribute('value',document.loginForm.pass.value);
var domain = document.createElement("input"); //input element, Submit button
domain.setAttribute('type',"text");
domain.setAttribute('name',"domain");
domain.setAttribute('value',document.loginForm.domain.value);
f.appendChild(user);
f.appendChild(pass);
f.appendChild(domain);
host = document.dpForm.dpAddress[i].value;
address = "https://"+host+":9090/sys.login";
f.setAttribute("target", "_blank");
f.setAttribute('action',address);
f.submit();
}
}
}
答案 0 :(得分:0)
实现此功能的一种方法是为窗口提供唯一的目标属性,并在提交表单之前将其打开。
function formSubmit1() {
len = document.dpForm.dpAddress.length
i = 0
for (i = 0; i < len; i++) {
if (document.dpForm.dpAddress[i].selected) {
// ... other code goes here
address = "https://" + host + ":9090/sys.login";
f.setAttribute("target", "window-" + i); // a unique id instead of "_blank"
f.setAttribute('action', address);
window.open(address, "window-" + i); // pop open a window with that same id and the form will submit into it
f.submit();
}
}
}
这是一个显示该技术的functional demo(确保您的弹出窗口拦截器被禁用)。