【发布时间】:2020-02-15 14:30:57
【问题描述】:
我发现了如何使用单个元素执行此操作,但我找不到任何可以更改页面正文 CSS 的内容。我正在尝试做一个东西,当你点击按钮时它会在明暗模式之间切换。
<!DOCTYPE html>
<button style="background-color: #252525;
border: 2px;
border-style: solid;
border-color: white;
color: white;
padding: 10px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
margin: 4px 2px;
cursor: pointer;" id="changethemebutton" onclick="changeTheme()">Change Theme</button>
function changeTheme() {
document.getElementById(".background").style.background = "black";
}
</script>
<style>
body{
background-color:white
}
</style>
【问题讨论】:
-
感谢
validation;) 请不要忘记upvote所有有用的答案 ;)
标签: javascript html css innerhtml