為什么不能創(chuàng)建函數(shù)?
<script type="text/javascript" language="javascript">
?window.onload =function(){
??var aDiv = document.getElementsByTagName("div");
??for (var i=0;i<aDiv.length;i++)
??aDiv[i].alpha = 30;
??aDiv[i].onmouseover = function(){
???changes(this,100);
??}
??aDiv[i].onmouseout = function(){
???changes(this,30);
??}
?}
?function changes(obj,num){
??clearInterval(obj.timer);
??obj.timer = setInterval(function(){
???var speed = 0;
???obj.alpha>num?speed=-10:speed=10;
???if(obj.alpha == num)
???{
????clearInterval(obj.timer);
???}
???else
???{
????obj.style.filter = "alpha(opacity:"+obj.alpha+speed+")";
????obj.style.opactiy = (obj.alpha + speed)/100;
???}
??},30)
?}
</script>
瀏覽器提示:Uncaught TypeError: Cannot set property 'onmouseover' of undefined
包括onmouseout也一樣,不能創(chuàng)建。這是為什么?
2016-02-20
你for循環(huán)少寫了花括號吧 沒有括起來
2016-02-21
obj.style.opactiy = (obj.alpha + speed)/100;?
obj.style.opacity = (obj.alpha + speed)/100;
你的 opacity 拼錯(cuò)了 仔細(xì)看看?
2016-02-20
為什么我加了括號還是沒出來效果呢?瀏覽器也沒有提示什么錯(cuò)誤。
2016-02-20
樓上的說的對