正确答案后重置选择选项

问题描述 投票:0回答:2

长时间听众,第一次来电...我有一个音乐测试要求用户识别音高,在正确答案之后,我需要选择选项的值重置为'禁用选中'。尝试过多次但没有运气。任何帮助将不胜感激!

$("#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>
javascript html
2个回答
0
投票

尝试

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

0
投票

我建议:

// 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;
© www.soinside.com 2019 - 2024. All rights reserved.