Uncaught TypeError: Cannot read property 'alpha' of undefined 报错解决

先附上报错的代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态改变图片的焦点</title>
</head>
<body>
<script type="text/javascript">
function visible(cursor,i) {
    if(i==0)
        cursor.filters.alpha.opacity=100;
    else
        cursor.filters.alpha.opacity=50;
}
</script>
<table border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center">
            <img src="images/3.jpg" border="0" style="filter:alpha(opacity=100)" onMouseOver="visible(this,1)" onMouseOut="visible(this,0)" width="148" HEIGHT="148">
        </td>
    </tr>
</table>
</body>
</html>

然后调试的时候就出现了这样的错误:
在这里插入图片描述
alpha没有定义。

这样解决:

把代码中的:

cursor.filters.alpha.opacity=100;

改为:

cursor.style.opacity=1;

完美解决问题。

发布了177 篇原创文章 · 获赞 282 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/lesileqin/article/details/103846441