我正在尝试编写一个JavaScript,它使id在单击时更改其id。基本上,我想创建一个黑暗模式切换按钮。但不知道我做错了什么。
HTML
<button id="nottebottone" class="notte">Attiva modalità notturna</button>CSS
#Sito {
    max-width: 1024px;
    margin: auto;
    text-align: center;
    background-color: rgb(221, 241, 235);
    border: black ridge;
    border-width: 0.03cm;
}我想把它改成:
#Nightmode {
    max-width: 1024px;
    margin: auto;
    text-align: center;
    background-color: rgb(0, 0, 0);
    border: rgb(255, 255, 255) ridge;
    border-width: 0.03cm;
    color: white;
}JavaScript:
let bottonedarkmode = document.getElementById("nottebottone");
function attivadarkmode() {
   if (document.div.id == "Sito") {
       document.div.id = "Nightmode";
   }
   else {
       documento.div.id = "Sito";
   }
}
bottonedarkmode.addEventListener('click', attivadarkmode);单击按钮nothing以启用id开关,但什么也不会发生。
发布于 2022-11-03 13:14:01
我希望这将有助于您更改身份证:
document.getElementById('nottebottone').id = 'Nightmode';https://stackoverflow.com/questions/74303562
复制相似问题