[英]Reset select option after correct answer
Long time listener, first time caller...I have a music test that asks the user to identify a pitch and after the correct answer, I need the select option's value to reset to 'disabled selected.' 长时间的聆听者,第一次的呼叫者...我有一个音乐测试,要求用户识别音高,并且在正确答案后,我需要将select选项的值重置为“ disabled selected”。 Have tried multiple things but no luck.
尝试过很多事情,但没有运气。 Any help would be greatly appreciated!
任何帮助将不胜感激!
$("#pitchBtn").click(function() { if (gameFinished) { // Clear the value of the option in the select element here } }
<select id="selectText"> <option value="" disabled selected>Enter your guess</option> <option value="C"></option> <option value="D">D</option> <option value="E">E</option> </select>
Try 尝试
var element = document.getElementById('selectText');
element.value = "";
I'd suggest: 我建议:
// cache the relevant <option> element,
// retrieve that element using
// document.querySelectorAll() to select
// the first, if any, element matching the
// supplied CSS selector:
let defaultOption = document.querySelectorAll('option[value=""]');
// set the 'selected' property to true:
defaultOption.selected = true;
// set the 'disabled' property to true:
defaultOption.disabled = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.