1 回答

TA貢獻1795條經(jīng)驗 獲得超7個贊
您可以選擇第一個選項并將其selected屬性更改為 true ,如下所示:
function clear_value() {
$('#ddID option[value=""]').prop('selected', true);
}
$('#clear').on('click', (e) => {
e.preventDefault();
clear_value();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
<label for="ddID">Select list:</label>
<select id="ddID" class="selectpicker mdb-select md-form" required>
<option value="" disabled selected></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<button id="clear">Clear Value</button>
添加回答
舉報