<script type="text/javascript">
window.onload=function(){
var odiv=document.getElementsByTagName("div");
for(var i=0;i<odiv.length;i++){
odiv[i].alpha=30;
odiv[i].onmoseover=function(){
statemove(this,100);
}
odiv[i].onmoseout=function(){
statemove(this,30);
}
}
}
function statemove(obj,long){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=0;
if(obj.alpha>long){
speed=-10;
} else{
speed=10;
}
if(obj.alpha==long) {
clearInterval(obj.timer);
}else{
obj.alpha+=speed;
obj.style.filter="alpha(opacity:'+obj.alpha+')";
obj.style.opacity=obj.alpha/100;
}
},30)
}
楼上的只是一个错误,最主要的是你把onmouseover写成了onmoseover,(双引号与单引号在该语言中是没什么太大的区别,但你上述写法就是明显错误的,引号之间要互相匹配,单配单,双配双,如果找你照你写的就相当于把alpha(opacity:'+obj.alpha+')该字符串赋给了前面的变量)。
obj.style.filter="alpha(opacity:'+obj.alpha+')";
这句话有问题,要改为:obj.style.filter = 'alpha(opacity:' + obj.alpha + ')';