gpt4 book ai didi

javascript - 在 jquery 中使用 optgroup 删除项目多选

转载 作者:行者123 更新时间:2023-11-30 08:42:54 25 4
gpt4 key购买 nike

有没有办法使用 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()

Fiddle

编辑

当你使用 multiSelect插件,需要使用.multiSelect('refresh')方法

$('#users').empty().multiSelect('refresh'); 

Updated Fiddle

关于javascript - 在 jquery 中使用 optgroup 删除项目多选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24429699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com