簡單的實現(xiàn)一下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Remove Color</title>
<style>
.box {
width: 100px;
height: 100px;
border: 2px black solid;
padding: 10px;
margin: 10px;
}
#green {
background-color: green;
}
#red {
background-color: red;
}
</style>
<script>
function removeColor() {
document.getElementById("green").style.backgroundColor = "white";
document.getElementById("red").style.backgroundColor = "white";
}
</script>
</head>
<body>
<p id="green" class="box">綠盒子</p>
<p id="red" class="box">紅盒子</p>
<button type="button" onclick="removeColor()">清除顏色</button>
</body>
</html>