简体   繁体   中英

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.' 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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