js实现点击按钮切换背景颜色
js实现点击切换背景颜色<!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
·
js实现点击切换背景颜色
<!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 = body1.style.backgroundColor = "red";
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>
更多推荐
已为社区贡献3条内容
所有评论(0)