有没有办法使用 jquery 清除所有 option 和 optgroup HTML 元素?
我的 HTML select 元素是这样的,
<select id="users" name="multiselect" multiple="multiple" style="width:382px;" >
<optgroup id="groupadmin" label="Group Admin"></optgroup>
<optgroup id="systemusers" label="System User"></optgroup>
</select>
最佳答案
您可以使用 .empty()
Description: Remove all child nodes of the set of matched elements from the DOM.
代码
$('#users').empty()
编辑
当你使用 multiSelect插件,需要使用.multiSelect('refresh')
方法
$('#users').empty().multiSelect('refresh');
关于javascript - 在 jquery 中使用 optgroup 删除项目多选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24429699/