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

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

更新控制 html 的變量時(shí)無法讀取未定義錯(cuò)誤的屬性“添加”

更新控制 html 的變量時(shí)無法讀取未定義錯(cuò)誤的屬性“添加”

qq_笑_17 2022-06-09 11:08:07
我使用數(shù)字作為元素 id,在 js 中由 i 表示,一旦按下開始按鈕,它應(yīng)該隱藏標(biāo)題屏幕,更新 i,然后從新的 i 元素中刪除隱藏類(隱藏元素)(問題1)和菜單欄元素。問題 1 和菜單欄應(yīng)留在屏幕上。但是,菜單欄加載,但問題沒有,并彈出錯(cuò)誤。無法讀取未定義的屬性“添加”// variablesvar i = 0;var id = document.getElementById(i.toString());var next = document.getElementById("next");// hiding menu and other screensmenuBar.classList.add('hide');next.classList.add('hide');document.getElementById("1").setAttribute("class", "hide");document.getElementById("2").setAttribute("class", "hide");document.getElementById("3").setAttribute("class", "hide");document.getElementById("4").setAttribute("class", "hide");document.getElementById("5").setAttribute("class", "hide");// show the next screen when the next button is pressedfunction nextScreen() {  id.classList.add('hide');  if (i == 0) {    menuBar.classList.remove('hide');  }  i ++;    next.classlist.add('hide');  id.classList.remove('hide');}start.onclick = nextScreen;next.onclick = nextScreen;    <div class="container">      <!-- title screen -->      <div id='0' class='title'>        <h1>          Welcome to<br>the<br><strong>IMPOSSIBLE QUIZ</strong>        </h1>        <button id='start' class='green button'>          START        </button>      </div>            <!-- question 1 -->      <div id='1' class='question'>        <span class='questionIndicator'>          Question 1        </span>        <br>        <h2>          What is after        </h2>        <button id='secretAnswer' class='secret'>          ...?        </button>        <button id='q1WrongAnswer' class='answer button'>          this?        </button>        <button id='q1WrongAnswer' class='answer button'>          the answer        </button>        <button id='q1WrongAnswer' class='answer button'>          no idea        </button>      </div>
查看完整描述

1 回答

?
30秒到達(dá)戰(zhàn)場(chǎng)

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

ID 為 2-5 的元素尚不存在,因此您無法調(diào)用setAttribute()它們。

另外,next.classlist.add('hide')應(yīng)該是next.classList.add('hide')(camelCase)


查看完整回答
反對(duì) 回復(fù) 2022-06-09
  • 1 回答
  • 0 關(guān)注
  • 187 瀏覽
慕課專欄
更多

添加回答

舉報(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)