2013-04-23 60 views
2

阅读列出了多个IP地址的列表框(dpAddress)。我选择其中的几个,并且想要使用以另一种形式(loginForm)提供的username-password-domain向每个选定的IP发送请求。我已经验证,如果我在列表中选择了2个IP地址,则循环工作2次。但它只打开一个新选项卡。使用不同的值多次提交HTML表格

我想在浏览器的同一窗口中打开多个选项卡,并在提交表单后显示结果。我怎样才能做到这一点?得到这个工作

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

一种方法是给窗口一个唯一的目标属性,并且事先打开他们提交表单。

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

+0

我在2个IP地址的Chrome中试过这个。一个是在同一个窗口中打开一个新标签,其次是打开一个新窗口。我希望两者都应该在新标签中打开。 – 2013-04-23 03:59:57