繁体   English   中英

正确答案后重设选择选项

[英]Reset select option after correct answer

长时间的聆听者,第一次的呼叫者...我有一个音乐测试,要求用户识别音高,并且在正确答案后,我需要将select选项的值重置为“ disabled selected”。 尝试过很多事情,但没有运气。 任何帮助将不胜感激!

 $("#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> 

尝试

var element = document.getElementById('selectText');
element.value = "";

我建议:

// 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM