求助?。?!
<!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>
為什么會(huì)顯示
width is not defined
2016-10-20
不好意思,又試了一下,object.style.width這樣才是對(duì)的,也不知道剛是怎么回事。只需要在26行的width加上'’就行了
2016-10-20
js里object.style.attr這種不需要"",而且不加""一般都是變量
2016-10-20
百度之后發(fā)現(xiàn)width這個(gè)屬性js里面只能object.width這樣用,還有26行的width應(yīng)該加''