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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在瀏覽器首選項(xiàng)中存儲(chǔ) CSS 類(lèi)?

如何在瀏覽器首選項(xiàng)中存儲(chǔ) CSS 類(lèi)?

九州編程 2023-07-29 13:41:03
(HTML、CSS、腳本,按順序)<center><a href="FBLINK" class="fa fa-facebook"></a><a href="TWITTERLINK" class="fa fa-twitter"></a><button class="button" onclick="myFunction()">&#9680;</button></center><style>.dark-mode {? background-color: #262626;? color: #d9d9d9;}.dark-mode a, .dark-mode span, .dark-mode h2 a, .dark-mode h1, .dark-mode h2, .dark-mode h3, .dark-mode h4, .dark-mode h5, .dark-mode h6, .dark-mode .post-box-title, .dark-mode strong.tag-heading {? color: #d9d9d9;}.dark-mode div#sidebar h2 span {? background-color: #262626;? border-color: #e5e5e5;}.dark-mode #sidebar .widget {? border-color: #e5e5e5;}.dark-mode .post-entry, .dark-mode .entry-meta {? border-bottom: 1px solid rgba(229,229,229,0.2);}.dark-mode div#blog-pager {? color: #d9d9d9;? background-color: #323232;}</style><script>function myFunction() {? ?var element = document.body;? ?element.classList.toggle("dark-mode");}</script>問(wèn)題是,我想將這些暗模式設(shè)置存儲(chǔ)在用戶(hù)瀏覽器上。已經(jīng)嘗試過(guò)sessionStorageand localStorage,但不確定我是否在正確的位置使用了代碼,并使用了正確的鍵/值組合(我有:鍵是&ldquo;style&rdquo;或&ldquo;class&rdquo;,值是&ldquo;dark-mode&rdquo;) 。是在這些<script>標(biāo)簽之間嗎?是在正確的 JavaScript 標(biāo)簽之間嗎?是在那段代碼里嗎?現(xiàn)在,我們將其用作localStorage主要設(shè)置。希望我說(shuō)得足夠清楚,感謝您的幫助!
查看完整描述

1 回答

?
翻閱古今

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以隨意命名本地存儲(chǔ)鍵,但請(qǐng)記住對(duì)值進(jìn)行相應(yīng)的操作。


<button onclick="toggleMode()">Toggle theme</button>


<script>

// Theme mode key name

const LS_THEME_KEY = "theme_mode";

// Possible theme mode local storage values

const THEME_MODE_LIGHT = 0;

const THEME_MODE_DARK = 1;

// Class to be applied when dark mode is active

const BODY_DARK_MODE_CLASS = "dark-mode";

// Default theme

const DEFAULT_THEME_MODE = THEME_MODE_DARK;


// Look up current theme mode and modify the body

// tag class list accordingly.

const syncBodyClassList = (setValue) => {

  const currThemeMode = setValue !== undefined ? setValue : parseInt(localStorage.getItem(LS_THEME_KEY) || DEFAULT_THEME_MODE);

  if (currThemeMode === THEME_MODE_DARK) {

    // turn the dark theme on

    document.body.classList.add(BODY_DARK_MODE_CLASS);

  } else {

    // turn the dark theme off

    document.body.classList.remove(BODY_DARK_MODE_CLASS);

  }

};


const setThemeMode = (mode) => {

  localStorage.setItem(LS_THEME_KEY, mode);

  syncBodyClassList(mode);

}


// Toggle current theme and save it into the local storage

function toggleMode() {

  const currentValue = parseInt(localStorage.getItem(LS_THEME_KEY) || DEFAULT_THEME_MODE);

  if (currentValue === THEME_MODE_DARK) {

    setThemeMode(THEME_MODE_LIGHT);

  } else {

    setThemeMode(THEME_MODE_DARK);

  }

}


const initPage = () => {

  syncBodyClassList();

}


initPage();

</script>


查看完整回答
反對(duì) 回復(fù) 2023-07-29
  • 1 回答
  • 0 關(guān)注
  • 114 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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