所以我才开始学习 JavaScript。当我点击“点击我!”时,我的警告框没有弹出!
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JAVASCRIPT</title>
</head>
<body>
<a href="#" id="anchor">Click Me!</a>
<script type="text/javascript">
var anchor = getElementById('anchor');
// or anchor = getElementsByTagName('a') then do ('a')[0]
anchor.addEventListener('click', doSomething, false);
function doSomething() {
alert('clicked');
}
</script>
</body>
</html>