Uncaught TypeError: Cannot read property 'currentStyle' of undefined"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
#div1{
width:200px;
height: 100px;
background: yellow;
margin-top: 10px;
border:5px solid black;
font-size: 12px;
filter:alpha(opacity=30);
opacity: 0.3;
}
</style>
<script>
window.onload = function(){
var div1=document.getElementById("div1");
div1.onmouseover=function(){
move(this,"width",400);
}
div1.onmouseout=function(){
move(this,"width",200);
}
}
var timer=null;
function move(obj,attr,target){
clearInterval(timer);
timer=setInterval(function(){
var icur =0;
if (attr = "opacity") {
icur = Math.round(parseFloat(getstyle(obj.attr))*100);
} else{
var icur = parseInt(getstyle(obj,attr));
}
var speed =(target-icur)/8;
speed =speed>0?Math.ceil(speed):Math.floor(speed);
if(target==icur){
clearInterval(timer);
}else{
if (attr = "opacity") {
obj.style.filter ="alpha(opacity:"+(icur+speed)+")"
obj.style.opacity = (icur+speed)/100;
} else{
obj.style[attr] = icur+speed+"px";
}
}
},30)
}
function getstyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
</script>
</head>
<body>
<div id="div1" >font-size</div>
</body>
</html>
一直报错:Uncaught TypeError: Cannot read property 'currentStyle' of undefined"
谁能告诉我为什么啊!!