2017-07-15 108 views
0

在HW項目上工作,我一直按照步驟嘗試獲取此確認窗口彈出,但無法弄清楚。我沒有得到任何控制檯錯誤,所以我認爲我的代碼只是在某處破碎。確認窗口的問題

<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <meta charset="utf-8" /> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
 
    <link rel="stylesheet" href="styles.css" /> 
 
    <script src="modernizr.custom.05819.js"></script> 
 
</head> 
 

 
<body> 
 
    <article> 
 
     <h2>Change of address form</h2> 
 
     <form> 
 
      <fieldset id="contactinfo"> 
 
       <label for="addrinput"> 
 
      Street Address 
 
      </label> 
 
       <input type="text" id="addrinput" name="Address" /> 
 
       <label for="cityinput"> 
 
      City 
 
      </label> 
 
       <input type="text" id="cityinput" name="City" /> 
 
       <label for="stateinput"> 
 
      State/Province 
 
      </label> 
 
       <input type="text" id="stateinput" name="State" /> 
 
       <label for="zipinput"> 
 
      Zip/Postal Code 
 
      </label> 
 
       <input type="number" id="zipinput" name="Zip" /> 
 
      </fieldset> 
 
      <fieldset id="submitsection"> 
 
       <input type="button" id="submit" value="Submit" /> 
 
      </fieldset> 
 
     </form> 
 

 
    </article> 
 
    <script> 
 
     function processInput() { 
 
      var propertyWidth = 300; 
 
      var propertyHeight = 100; 
 
      var winLeft = ((screen.width - propertyWidth)/2); 
 
      var winTop = ((screen.height - propertyHeight)/2); 
 
      var winOptions = "width=300,height=100"; 
 
      winOptions += ",left=" + winLeft; 
 
      winOptions += ",top=" + winTop; 
 
      window.open("confirm.htm", "confirm", winOptions); 
 
     } 
 

 
     function createEventListener() { 
 
      var submitButton = document.getElementById("submit"); 
 
      if (submitButton.addEventListener) { 
 
       submitButton.addEventListener("click", processInput, 
 
        false); 
 
      } else if (submitButton.attachEvent) { 
 
       submitButton.attachEvent("onclick", processInput); 
 
      } 
 
     } 
 

 
     if (window.addEventListner) { 
 
      window.addEventListener("load", createEventListener, false); 
 
     } else if (window.attachEvent) { 
 
      window.attachEvent("onload", createEventListener); 
 
     } 
 
    </script> 
 
</body> 
 

 
</html>

+3

你定義兩個函數,但你沒有任何地方執行。你有一堆永遠不會執行的代碼。 –

+0

我認爲這是eventlisteners的要點,要執行onclick提交按鈕。 –

+3

如果它們沒有包含在一個永遠不會被調用的函數中,它們會。 – j08691

回答

1

移動的createEventListener超出這個代碼:

if (window.addEventListner) { 
    window.addEventListener("load", createEventListener, false); 
} else if (window.attachEvent) { 
    window.attachEvent("onload", createEventListener); 
} 
+0

我認爲這已經修復過,但我意識到我已經添加了processInput函數到我的按鈕,以確保代碼工作。將此代碼移出createEventListener函數並從onClick提交按鈕中刪除processInput函數後,代碼仍未執行。 –

+0

@DanielMiller,將你的'