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

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

為什么輸入值顯示在控制臺(tái)中,但不顯示在下拉框中?

為什么輸入值顯示在控制臺(tái)中,但不顯示在下拉框中?

慕尼黑5688855 2023-04-27 17:15:08
我構(gòu)建了一個(gè)接受用戶輸入的基本報(bào)告程序,將此輸入添加到一系列添加到下拉列表的段落中。然后將選擇添加到數(shù)組中并打印在最終報(bào)告中。這是該程序的 JFiddle。正如您將看到的,您的輸入會(huì)打印在控制臺(tái)中,但不會(huì)被拉到下拉列表中。你能幫我弄清楚為什么嗎?function populateSelects(dropDownConfig) {    console.log(`I can get the student name here, but not in the dropdown box. Your name is ${studentName}.`);for (let di = 0; di < dropDownConfig.length; di++) {  for (let i = 0; i < dropDownConfig[di].categoryOptions.length; i++) {    let opt = dropDownConfig[di].categoryOptions[i];    let el = document.createElement("option");    el.text = opt;    el.value = opt;    document.getElementById(dropDownConfig[di].id).add(el);  }}}該函數(shù)似乎可以正常工作,但不適用于 studentName/inputStudentName 的值。謝謝!
查看完整描述

1 回答

?
HUWWW

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

恕我直言,我已經(jīng)稍微更改了您的代碼以使其更短且更具可讀性。我所做的主要更改是使用占位符文本而不是變量,并在創(chuàng)建選項(xiàng)時(shí)將其替換為 studentName。


let options= {

  progress: ['%NAME% has made excellent progress', '%NAME% has made good progress', '%NAME% has made poor progress'],

  behaviour: ['%NAME% has excellent behaviour', '%NAME% has good behaviour', '%NAME% has poor behaviour'],

  attendance: ['%NAME% has excellent attendance', '%NAME% has good attendance', '%NAME% has poor attendance'],

  punctuality: ['%NAME% has excellent punctuality', '%NAME% has good punctuality', '%NAME% has poor punctuality'],

  improvements: ['%NAME% should carry on as they have', '%NAME% could make some improvements', '%NAME% must improve']

}


let dropDownConfig = ["progress", "behaviour", "attendance", "punctuality", "improvements"];


function populateSelects(dropDownConfig) {

  dropDownConfig.forEach(config => {

    let select = document.querySelector(`#${config}Dropdown`);

    options[config].forEach(text => {

        let option = document.createElement("OPTION");

        text = text.replace("%NAME%", studentName);

        option.text = text;

        option.value = text;

        select.appendChild(option);

    })

  })

}


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

添加回答

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