日期:2014-05-16  浏览次数:20390 次

实在想不通,谁帮我看看啊
<html>
<head>
<script   type= "text/javascript ">
var   fnClick1=function(){
alert( "haha ");
};
var   oDiv=document.getElementById( "ddd ");
oDiv.onclick=fnClick1;
</script>
</head>
<body>
<div   id= "ddd "> yiyiyi </div>
</body>
</html>
运行的时候老提示oDiv对象为空或不存在,怎么回事啊

------解决方案--------------------
或:

<script type= "text/javascript ">
var fnClick1=function(){
alert( "haha ");
}
window.onload=function(){
var oDiv=document.getElementById( "ddd ");
oDiv.onclick=function(){
fnClick1();
}
}

</script>
------解决方案--------------------
<html>
<head>

</head>
<body>
<div id= "ddd "> yiyiyi </div>
<script type= "text/javascript ">
var fnClick1=function(){
alert( "haha ");
}
var oDiv=document.getElementById( "ddd ");
oDiv.onclick=fnClick1;
</script>
</body>
</html>