<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
fieldset{
width: 200px;
margin: 0 auto;
}
</style>
</head>
<body>
<fieldset>
<legend>控制页面背景色</legend>
<div class="btns">
<button id="red">红色</button>
<button id="blue">蓝色</button>
<button id="green">绿色</button>
</div>
</fieldset>
</body>
</html>
<script>
button_red = document.getElementById('red')
button_blue = document.getElementById('blue')
button_green = document.getElementById('green')
button_red.onclick = function(){
document.body.style.backgroundColor = "red"
}
button_blue.onclick = function(){
document.body.style.backgroundColor = "blue"
}
button_green.onclick = function(){
document.body.style.backgroundColor = "green"
}
</script>
css html js 点击按钮修改背景颜色
最新推荐文章于 2024-07-04 20:21:08 发布