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

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

更改按鈕的背景顏色(開/關(guān))

更改按鈕的背景顏色(開/關(guān))

動(dòng)漫人物 2023-10-30 19:41:45
我已經(jīng)審查過這個(gè)問題,但我沒有使用角度。到目前為止,這是我的代碼:<button id='Bx' type="button" onclick='toggleClickedBuz("Bx", "#Bx")'>Bx</button><button id='By' type="button" onclick='toggleClickedBuz("Bx", "#Bx")'>By</button><button id='Bz' type="button" onclick='toggleClickedBuz("Bx", "#Bx")'>Bz</button>我的 JS 是這樣的:function toggleClickedBuz( bizStr , id ) {    if(clickedBusinesses.includes(bizStr)){       // removing duplicate element from that array, dependant on button pressed       clickedBusinesses = clickedBusinesses.filter( cb => cb !== bizStr );       document.getElementById( id ).style.backgroundColor='white';    }else{        // else push it to the array       clickedBusinesses.push(bizStr)       document.getElementById( id ).style.backgroundColor='red';    }    console.log(clickedBusinesses)}
查看完整描述

4 回答

?
FFIVE

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

但我收到此錯(cuò)誤:


未捕獲的類型錯(cuò)誤:無法讀取 null 的屬性“樣式”


盡管我的CSS中有這個(gè):


.canvas .button-box button {

    border-radius: 2px;

    width: 10vw;

    margin-top: 0.5vh;

    background-color: whitesmoke;

}

有什么建議嗎?


查看完整回答
反對(duì) 回復(fù) 2023-10-30
?
撒科打諢

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

給出以下 HTML

<button id='Bx' type="button" onclick='toggleClickedBuz("Bx", "#Bx")'>Bx</button>

您將#Bx作為 id 參數(shù)傳遞給切換函數(shù)。這會(huì)導(dǎo)致 js 調(diào)用:

document.getElementById("#Bx");

但該getElementById函數(shù)不需要#前綴。嘗試將您的 HTML 更改為

<button id='Bx' type="button" onclick='toggleClickedBuz("Bx", "Bx")'>Bx</button>

修復(fù)您當(dāng)前的問題??


查看完整回答
反對(duì) 回復(fù) 2023-10-30
?
繁星點(diǎn)點(diǎn)滴滴

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

很簡單,你不需要#in toggleClickedBuz("Bx", "#Bx"). 放id無#. 該函數(shù)getElementById()已經(jīng)引用了 id。所以你不需要指定使用#.


你的 HTML 應(yīng)該是這樣的


<button id='Bx' type="button" onclick='toggleClickedBuz("Bx", "Bx")'>Bx</button>

<button id='By' type="button" onclick='toggleClickedBuz("Bx", "Bx")'>By</button>

<button id='Bz' type="button" onclick='toggleClickedBuz("Bx", "Bx")'>Bz</button>


查看完整回答
反對(duì) 回復(fù) 2023-10-30
?
慕標(biāo)5832272

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

您不需要#在按鈕中。這么多就足夠了:


<button id='Bx' type="button" onclick='toggleClickedBuz("Bx","Bx")'>Bx</button>

<button id='By' type="button" onclick='toggleClickedBuz("Bx","Bx")'>By</button>

<button id='Bz' type="button" onclick='toggleClickedBuz("Bx","Bx")'>Bz</button>

#是一個(gè) CSS 選擇器,用于選擇 HTMLid元素。您可以通過以下方式在 CSS 中引用它們:


#Bx {

  color: #AAAAAA;

}


查看完整回答
反對(duì) 回復(fù) 2023-10-30
  • 4 回答
  • 0 關(guān)注
  • 153 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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