这很简单,但是当我执行网络时,根本就没有警报!我只是像youtube的视频那样做,但是当我想和他做同样的事情时没有回应。
// this is my html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="shiyan.css">
</head>
<body>
<header>
<h1>Javascript Event</h1>
</header>
<main>
<h4> Add Numbers:</h4>
<p>
<input id = "num-one"> + <input id = "num-two">
</p>
<p id = "add-sum"></p>
</main>
<script src="shiyan.js"></script>
</body>
</html>
//here is my shiyan.js in the same file of html
var numOne = document.getElementById("num-one");
var numTwo = document.getElementById("num-two");
var addSum = document.getElementById("add-sum");
numOne.addEventListener("click ", function(){
alert("hahahahaa");
});
答案 0 :(得分:0)
摆脱click
numOne.addEventListener("click", function(){
alert("hahahahaa");
});