【发布时间】:2016-09-27 02:26:22
【问题描述】:
点击重置按钮后如何从jquery多选中删除选定的项目?
<select data-placeholder="Select" id="options" class="chosen-select" maxwidth="50px" multiple tabindex="15" ></select>
我尝试了几种方法都没有运气。这是我的代码:
$("#options").multiselect('refresh');
$("#options").multiselect('clearSelection');
$('#options').multiSelect('deselect_all');
$("#options").find('option:selected').removeAttr("selected");
上图后仍然显示选中的项目,
任何帮助将不胜感激。
【问题讨论】:
-
该屏幕截图看起来不像多选 - 它看起来像已选择 (harvesthq.github.io/chosen) 或 tagit (aehlke.github.io/tag-it)...您是否 100% 确定正在使用哪个库?编辑:实际上基于类,它是一个选定的字段...使用
.chosen()方法,或将属性设置为false(即$("#options").find('option:selected').prop('selected',false)),而不仅仅是删除属性;然后触发更新:$("#options").trigger('chosen:updated');
标签: jquery reset multi-select jquery-chosen