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>Document</title> </head>
<body> <button id="btn">开</button> </body> <script>
var btnE = document.getElementById('btn'),
text;
btnE.addEventListener('click', function () {
text = btnE.innerText;
btnE.innerText = text === "开" ? "关" : "开";
text === "开" ? document.body.style.backgroundColor = "black" : document.body.style.backgroundColor = "white";
});
</script>
</html>
<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> <button id="btn">开</button> </body> <script>
var btnE = document.getElementById('btn'),
text;
btnE.addEventListener('click', function () {
text = btnE.innerText;
btnE.innerText = text === "开" ? "关" : "开";
text === "开" ? document.body.style.backgroundColor = "black" : document.body.style.backgroundColor = "white";
});
</script>
</html>
标签:body,style,btnE,js,背景色,backgroundColor,text,屏幕,document 来源: https://www.cnblogs.com/guoh0036/p/14975700.html