<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#hs {
width: 200px;
height: 200px;
background: gray;
}
</style>
<script>
var an1 = document.getElementById("an");
function rec() {
var bs = document.getElementById("hs");
bs.style.background = "red";
}
an1.onmouseover = rec;
</script>
</head>
<body>
<input id="an" type="button" value="按钮" />
<div id="hs">
</div>
</body>
</html>
3 回答
Anyone
TA贡献1条经验 获得超0个赞
script标签内部要加上window.onload = function(){ },把你的js代码放到这个大括号里边就可以了。或者就是把script标签放到</body>标签后边
添加回答
举报
0/150
提交
取消