javascript小练习-Firefox和低版本chrome下必须采用document方法获取到元素。

时间:2023-03-09 21:07:13
javascript小练习-Firefox和低版本chrome下必须采用document方法获取到元素。
在如下的代码中,Firefox和低版本的chrome浏览器,是会报错的,因为#div未定义。
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
#div1{width: 200px;height: 200px;background-color: aqua;display: none;}
</style>
</head>
<body>
<input type="button" value="按钮" onmouseover="div1.style.display = 'block'" onmouseout="div1.style.display = 'none'"/>
<div id="div1"></div>
</body>
</html>