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

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

如何使用 JavaScript 在特定單選按鈕上應(yīng)用條件

如何使用 JavaScript 在特定單選按鈕上應(yīng)用條件

慕森卡 2023-07-20 17:39:56
我想要的是,當(dāng)我單擊特定的紅色id 單選按鈕時(shí),它會(huì)向我顯示警報(bào),正如您在代碼中看到的那樣...在我的情況下,它沒(méi)有發(fā)生...問(wèn)題是什么以及如何對(duì)此進(jìn)行排序?<form>  What color do you prefer?<br>  <input type="radio" name="colors" id="red">Red<br>  <input type="radio" name="colors" id="blue">Blue</form><script>  if (document.getElementById("red").checked == true) {    alert('working');  }</script>
查看完整描述

3 回答

?
慕田峪7331174

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

你需要一個(gè)事件監(jiān)聽(tīng)器


document.getElementById("red").addEventListener("change", myAlert); 


function myAlert() {

    alert('working');

}

<form>

    What color do you prefer?<br>

    <input type="radio" name="colors" id="red">Red<br>

    <input type="radio" name="colors" id="blue">Blue

</form>


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

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

  1. 您需要事件偵聽(tīng)器 - 不建議使用內(nèi)聯(lián)事件處理程序

  2. 您需要決定要測(cè)試什么

這里有兩種跑步方式

它們是收音機(jī),所以我們不需要測(cè)試它們是否被檢查

window.addEventListener("load",function() { // when the page loads


  // testing clicking the RED only

  document.getElementById("red").addEventListener("click",function() {

    console.log("The specific Red event listener was invoked");

  });    


  // delegation

  document.querySelector("form").addEventListener("click",function(e) {

    const tgt = e.target;

    if (tgt.id==="red") console.log("Clicking in the form, we clicked the thing with ID red")

  })

});

<form>

  What color do you prefer?<br>

  <label><input type="radio" name="colors" id="red">Red</label><br>

  <label><input type="radio" name="colors" id="blue">Blue</label>

</form>


查看完整回答
反對(duì) 回復(fù) 2023-07-20
?
繁花不似錦

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

嘗試這樣:


<form>

  What color do you prefer?<br>

  <input type="radio" name="colors" id="red"/>Red<br>

  <input type="radio" name="colors" id="blue"/>Blue

</form>

<script>

document.getElementById("red").onchange = function() {

   alert('working');

}

</script>

單擊單選按鈕時(shí)需要一個(gè)事件處理程序來(lái)運(yùn)行該特定代碼。



查看完整回答
反對(duì) 回復(fù) 2023-07-20
  • 3 回答
  • 0 關(guān)注
  • 175 瀏覽
慕課專(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)