第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用按鈕更改網(wǎng)站的背景?

如何使用按鈕更改網(wǎng)站的背景?

手掌心 2021-06-08 14:15:57
我正在嘗試編寫一個需要使用按鈕更改背景的網(wǎng)站,但我無法...我創(chuàng)建了一個按鈕,可以在單擊按鈕時更改背景顏色,但是在添加圖像作為背景后,它不想更改背景顏色(顯然)...<head><style>:root{   --main-bg: url(https://www.the url of my bg.jpg);}</style> // creating a variable for the bg of my site<style>body {   background: var(--main-bg) repeat-x;}</style> // using this variable<script>      var colors = ["#2d2d2d", "#f2f2f2"];      var colorIndex = 0;      function changeColor() {          var col = document.getElementById("body");          if( colorIndex >= colors.length ) {              colorIndex = 0;          }          col.style.backgroundColor = colors[colorIndex];          colorIndex++;// the js script to change the bg color      }  </script><script>      function backgroundHiding() {         let root = document.documentElement;         root.addEventListener("onclick", e => {            if (--main-bg) =  "#2d2d2d" {            root.style.setProperty('--main-bg', " url(https://www.the urlof my bg.jpg)")         } else {            root.style.setProperty('--main-bg', "#2d2d2d")         }            // the js script to hide my img bg      }      </script><div class="button">      <body id='body'>            <button onclick="changeColor(); backgroundHiding();" class="lightbutton"><span>Turn On/Off the lights</span> </button></div> // creating the button that interact with the two js functions</head>我預(yù)計它會起作用,但是......呃......不它有時有效,比如每 100 次 1 次,我不知道為什么......如果有人能幫助我,我會很感激!https://stackblitz.com/edit/typescript-ppvsvl?embed=1&file=index.html
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號