当单击“其他”时,我试图使文本区域字段出现在我的选项列表下方,但我无法使我的 JS 函数工作。
我究竟做错了什么?
function showOtherJobRole(nameOfJob) {
if (nameOfJob == "other-title") {
const otherJobTitle = document.getElementById("other-title").value;
if (otherJobTitle == nameOfJob.value) {
document.getElementById("showOtherJobRole").style.display = "block";
} else {
document.getElementById("showOtherJobRole").style.display = "none";
}
}
else {
document.getElementById("showOtherJobRole").style.display = "none";
}
}
<fieldset>
<label for="title">Job Role</label>
<select id="title" name="user-title" onchange="showOtherJobRole(this);">
<option value="" disabled="disabled" selected>--</option>
<option value="full-stack js developer">Full Stack JavaScript Developer</option>
<option value="front-end developer">Front End Developer</option>
<option value="back-end developer">Back End Developer</option>
<option value="designer">Designer</option>
<option value="student">Student</option>
<option id="other-title">Other</option>
</select>
</fieldset>
<div id="showOtherJobRole" style="display: none">
<textarea name="otherJobText" id="otherJobText" cols="40" placeholder="Your Job Role" rows="4"></textarea>
</div>
ABOUTYOU
慕莱坞森
哈士奇WWW
相关分类