請(qǐng)問是哪里出錯(cuò)呢?感覺沒錯(cuò)啊。
<!DOCTYPE?html>
<html>
<head>
????<title></title>
</head>
<body>
<input?type="button"?value="This?is?a?code"?id="one">
<input?type="button"?value="This?is?a?code"?id="two"?onClick="a()">
<input?type="button"?value="This?is?a?code"?id="three">
<script?type="text/javascript">
????var?one?=?document.getElementById("one");
????one.onClick=function?()
????{
????????alert('kekeke');
????}
????
????function?a()
????{
????????alert('hahaha');
????}
????var?three?=?document.getElementById('three');
????three.addEventListener('click',a,false);
????
????var?four?=?document.getElementById("four");
????four.attachEvent('onclick',a);
</script>
</body>
</html>
2015-09-04
第一個(gè):one.onclick;onclick字母小寫;
第四個(gè):你有input按鈕嗎?
還有測(cè)試addEventListener和attachEvent要分開瀏覽器測(cè)試,先注釋掉一個(gè)