1 回答
TA贡献1795条经验 获得超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>
添加回答
举报