<!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>换背景颜色</title>
<style>
#button1 {
background-color: red;
}
#button2 {
background-color: yellow;
}
#button3 {
background-color: blue;
}
</style>
<script>
window.onload = function() {
button1.onclick = function() {
var test =
button1.innerHTML = test;
/* alert("2"); */
}
button2.onclick = function() {
var test = body1.style.backgroundColor = "yellow";
button1.innerHTML = test;
}
button3.onclick = function() {
var test = body1.style.backgroundColor = "blue";
button1.innerHTML = test;
}
}
</script>
</head>
<body id="body1">
<input type="button" value="button1" id="button1">
<input type="button" value="button2" id="button2">
<input type="button" value="button3" id="button3">
</body>
</html>
转载:js实现点击按钮切换背景颜色_js点击改变背景颜色_hahahahadoop的博客-CSDN博客
https://blog.csdn.net/wj624/article/details/118735913