<html>
<style>
#myA {
height: 300;
width: 300;
background: green;
}
</style>
<body>
<script language="JavaScript">
document.getElementById('myA').onmousedown = function() {
var a = document.getElementById('myA');
console.log(a);
}
</script>
<div id="myA"></div>
</body>
</html>
請問,爲什麼上面的代碼不工作?當我想寫console.log時,我什麼也沒有,空值。document.getElementById()。onmousedown不起作用
另請參見[爲什麼jQuery或諸如'getElementById'的DOM方法未找到該元素?](http://stackoverflow.com/q/14028959/1048572) – Bergi 2013-02-13 19:26:13