小白求大神指点
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#box{
width: 200px;
height: 200px;
background-color: #000;
}
</style>
<script>
window.onload = function () {
function Color(color) {
var box = document.getElementById("box");
box.style.backgroundColor = color;
}
}
</script>
</head>
<body>
<input type="button" value="红" onclick="Color('red')">
<input type="button" value="绿" onclick="Color('green')">
<input type="button" value="蓝" onclick="Color('blue')">
<div id="box"></div>
</body>
</html>
求大神指点为什么去掉window.onload后js无法运行,会失效,急急