2017-07-15 69 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,将你的'