答案 0 :(得分:3)
您可以在选择中添加ID。然后添加一个函数clearSelection
,以便在单击按钮时触发。
function saveSelection(value) {
}
function clearSelection() {
//This will select the first option of the select
document.getElementById('select-baseline').options[0].selected = 'selected';
}
<select id='select-baseline' onchange="saveSelection(value)">
<option value="" selected disabled hidden>Choose Baseline</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<button type="button" onClick="clearSelection()">Reset menu</button>
答案 1 :(得分:1)
将所有这些代码放在form
标记内。这样,您就可以将明确功能应用于select
代码,并将button
类型更改为reset
<form>
<select>
...
</select>
<button type="reset">Reset Menu</button>
</form>
答案 2 :(得分:0)
<select id="menu" onchange="saveSelection(value)">
<option value="" selected disabled hidden>Choose Baseline</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<button type="button" onclick="resetMenu()">Reset menu</button>
<script src="test.js"></script>
的JavaScript
function resetMenu() {
var element = document.getElementById('menu');
element.value = '';
}