按钮改变颜色:
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script> | |
function changeColor(str){ | |
var body=document.getElementById("f"); | |
body.style.backgroundColor=str; | |
} | |
</script> | |
</head> | |
<body id="f"> | |
<button onclick="changeColor('blue')">蓝色</button> | |
<button onclick="changeColor('green')">绿色</button> | |
<button onclick="changeColor('red')">红色</button> | |
</body> | |
</html> | |