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

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

Javascript 按鈕 onclick 更改

Javascript 按鈕 onclick 更改

HUX布斯 2021-10-29 10:42:21
我需要制作一個(gè)按鈕,當(dāng)點(diǎn)擊執(zhí)行一個(gè)功能,然后在更改之后,就好像它是一個(gè)開(kāi)/關(guān)按鈕一樣,它在每個(gè)與 css 一起使用的按鈕中執(zhí)行 2 個(gè)功能 1,并且僅使用純 javascript<!DOCTYPE html><html><head></head><body><p id="red"> Paragrafo 01</p><input type="button"  value= "cor" onclick="mudarred();" /> <script>    function mudarred(){  if()        document.getElementById('red').style.color="red";    else    document.getElementById('red').style.color="blue";    }    </script></body></html>
查看完整描述

2 回答

?
繁花如伊

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

不確定“僅使用純 JS”classList.toggle()是什么意思,但對(duì)此非常有用。我還建議您將樣式保留在 CSS 中,而不是 JS 或 HTML。


const buttonElement = document.querySelector('.js-toggle-button')

const paragraphElement = document.querySelector('.js-paragraph')


buttonElement.addEventListener('click', () => {

  paragraphElement.classList.toggle('paragraph--off')

})

.paragraph {

  color: red;

}


/* Overrides because of specificity */

.paragraph--off {

  color: blue;

}

<p class="js-paragraph paragraph">Paragraph</p>

<button class="js-toggle-button">Toggle</button>


查看完整回答
反對(duì) 回復(fù) 2021-10-29
?
有只小跳蛙

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

我修改了你的 jsfidle檢查這個(gè)


let firstCall = true;

function mudarred(){

    if(firstCall){

        document.getElementById('red').style.color="red";

        firstCall= false;

    }else{

        firstCall=true;

        document.getElementById('red').style.color="blue";

    }

}


查看完整回答
反對(duì) 回復(fù) 2021-10-29
  • 2 回答
  • 0 關(guān)注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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