簡體   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