[英]How to refresh select without refreshing full page
Hello i want to refresh this select without refreshing all page您好,我想在不刷新所有页面的情况下刷新此选择
<select name="number" id="number">
<option value="1">first</option>
<option value="2">second</option>
<option value="3">third</option>
</select>
I had reset it because I needed it to perform a few tasks but to update it as in the beginning, I have to update all my page but I just want to refresh the combobox itself without having to refresh the page.我已经重置它,因为我需要它来执行一些任务,但要像一开始一样更新它,我必须更新我的所有页面,但我只想刷新组合框本身而不必刷新页面。 What code should I put ?我应该放什么代码?
If you want to reset the selection, please try this.如果您想重置选择,请尝试此操作。
$('#number').val('');
Or或者
$('select option:selected').removeAttr('selected');
If you want to remove all the option from the dropdown and make it empty, try this.如果您想从下拉列表中删除所有选项并将其设为空,请尝试此操作。
$('#number').empty();
If you have more than one 'select' you can always create a function and use this:如果您有多个“选择”,您可以随时创建一个函数并使用它:
const selects = this.elementRef.nativeElement.querySelectorAll('select');
selects.forEach(select => {
select.value = '';
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.