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

匆匆过客 提交于 2020-01-06 22:17:06

先附上报错的代码:

<!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;

完美解决问题。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!