-2
<html>
<head>
<title>test</title>
<script type="text/javascript">
function start(){
document.getElementById("first_div").onclick = function(){
document.getElementById("another_div").style.color = "red";
};
}
</script>
</head>
<body onload="start()">
<div id="first_div">first</div>
<div id="anoter_div">second</div>
</body>
</html>
當我點擊first_div,發生錯誤:爲什麼在匿名函數中改變DOM屬性不起作用?
TypeError: Result of expression 'document.getElementById("another_div")' [null] is not an object.
知道爲什麼這是不工作?
謝謝。
或更好的是,更正DIV ID中的原始錯別字... :) – 2011-06-14 08:15:08