1 回答
TA贡献1874条经验 获得超12个赞
恕我直言,我已经稍微更改了您的代码以使其更短且更具可读性。我所做的主要更改是使用占位符文本而不是变量,并在创建选项时将其替换为 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);
})
})
}
添加回答
举报