小白求大神指点

qq_37046350 qq_37046350 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<!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无法运行,会失效,急急
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
qq_37046350
JavaScript 87,984 成员 224,681 内容