在jQuery中用空数组替换后,列表框项目仍然保留 [英] ListBox items remains after replace by empty array in jQuery
本文介绍了在jQuery中用空数组替换后,列表框项目仍然保留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表框,我想由jQuery清除而不刷新页面.
I have a list box which I want to clear by jQuery without page refresh.
<asp:ListBox ID="lbComplaints" runat="server"
ClientIDMode="Static" SelectionMode="Multiple"
placeholder="Select Complaints" Style="width: 280px;" AppendDataBoundItems="True">
在按钮中单击
$('input[type="submit"]').click(function (e) {
e.preventDefault();
$("#lbComplaints").val([]);
)};
它没有显示任何错误,但是项目保留在先前的选择中.
It does not show any error but the items remain in previous selection.
我尝试了
$("#lbComplaints").empty();
但删除了列表框的所有数据,但是我不想删除选项,而是取消选择列表框值中的上一个选项,以便用户可以再次选择.我该怎么办?
but all the data of the Listbox is removed but I do not want to remove options but unselection of previous option in Listbox value so that user can select again. How can I do that?
通过我的使用方式
$('#lbComplaints').select2({
placeholder: 'select a state',
//tags: "true",
//allowClear: true,
theme: "classic"
});
推荐答案
但是在
由于我使用的是select2,因此jQuery无法清除所选项目,因此使用select2 $('#lbComplaints').select2('data', null);
这很好用
As i am using select2 jQuery cannot clear selected items so using select2 $('#lbComplaints').select2('data', null);
this works perfectly
这篇关于在jQuery中用空数组替换后,列表框项目仍然保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文