<!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>
</head>
<body>
<input id="btn" type="button" value="关灯">
<script>
var btn = document.getElementById("btn");
btn.onclick = function(){
if(btn.value == "关灯"){
document.body.style.backgroundColor = "black";
this.value = "开灯";
}else {
document.body.style.backgroundColor = "white";
this.value = "关灯";
}
};
</script>
</body>
</html>