2013-04-23 23 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