跳转至内容

BTEC IT 单元 20 - 网站设计/JavaScript/弹出框

来源:维基教科书,开放世界的开放书籍

弹出框(非结构化代码)

<input type="button" value="Click me" onclick="alert('Thanks... I feel much better now!');">

弹出框(结构化代码)

<head>
<script>
// Wait for DOM to load
document.addEventListener("DOMContentLoaded", function(event) {

  // Put the button into a variable
  var e = document.getElementById("go");
  
  // Wait for user to click the button  
  e.addEventListener("click", function() {
  
      // Do the alert box
      alert("Hello");
      
  }, false);
  
});
</script>
</head>
<body>
<form name="myForm">
  <input id="go" type="button" value="Click me">
</form>
</body>
华夏公益教科书