搞不懂錯(cuò)在哪里。。報(bào)錯(cuò)是21行 cannot set property“onmouseover”of null...
<!DOCTYPE html>
<html lang="en">
<head>
? ?<meta charset="UTF-8">
? ?<title>Title</title>
? ?<style>
*{margin: 0;padding: 0;}
? ? ? ?#div1{
? ? ? ? ? ?width:200px;
height: 200px;
background-color:red;
margin: 40px auto;
opacity:0.3;
filter:alpha(opacity:30);
cursor: pointer;
}
? ?</style>
? ?<script>
window.onload = function(){
? ? ? ? ? ?var oDiv=document.getElementById('#div1');
oDiv.onmouseover=function(){
? ? ? ? ? ? ? ?startMove(100);
};
oDiv.onmouseout=function(){
? ? ? ? ? ? ? ?startMove(30);
}
? ? ? ?};
var timer=null;
var apa=30;
function startMove(iTarget){
? ? ? ? ? ?var oDiv=document.getElementById("#div1");
clearInterval(timer);
timer=setInterval(function(){
? ? ? ? ? ? ? ?var speed=0;
if(apa>iTarget){
? ? ? ? ? ? ? ? ? ?speed=-10;
}
? ? ? ? ? ? ? ?else{
? ? ? ? ? ? ? ? ? ?speed=10;
}
? ? ? ? ? ? ? ?if(apa==iTarget){
? ? ? ? ? ? ? ? ? ?clearInterval(timer)
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?else{
? ? ? ? ? ? ? ? ? ?apa+=speed;
oDiv.style.filter="alpha(opacity:"+apa+")";
oDiv.style.opacity=apa/100;
}
? ? ? ? ? ?},30)
? ? ? ?}
2016-07-25
?var oDiv=document.getElementById('#div1'); ?不需要#號(hào)吧