求助!!!
<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> #div1{ background: red; width: 100px; height:100px; border:2px solid gray; } </style> <script type="text/javascript"> window.onload=function(){ var oDiv=document.getElementById("div1"); oDiv.onmouseover=function(){ startMove(0); } } function startMove(iTarget){ var timer; clearInterval(timer); var oDiv=document.getElementById("div1"); timer=setInterval(function(){ oDiv.style.width=parseInt(getStyle(oDiv,width))-1+'px'; },50); } function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; } else{ return getComputedStyle(obj,false)[attr]; } } </script> </head> <body> <div id="div1"></div> </body> </html>
为什么会显示
width is not defined