[英]How to remove SELECTED Listbox Item when click the Button using Jquery?
I have 2 Asp ListBox called lstLeft and listRowField
.我有 2 个名为lstLeft and listRowField
Asp ListBox 。 When user select the item from 1stLeft and click the button it will move to another listbox (listRowField) but with restriction (Some of the item shouldn't move) .当用户从1stLeft选择项目并单击按钮时,它将移动到另一个列表框(listRowField)但有限制(某些项目不应移动) 。
upto this I already made, that code is working fine .到目前为止,我已经做了,该代码工作正常。 When user select the restricted items and click the button, the selected items should be unselect again当用户选择限制项并单击按钮时,应再次取消选择所选项目
TotalQuantity from
1stLeft
is not allowed to move .1stLeft
TotalQuantity 不允许移动。 Once it shows the alert message, that selection color from1stLeft
should remove.一旦显示警报消息,1stLeft
中的选择颜色应删除。
I tried this code, but doesn't work我试过这段代码,但不起作用
$('#rightRow').click(function () {
var options = $("[id*=lstLeft] option:selected");
for (var i = 0; i < options.length; i++) {
if ($(options[i]).val() === 'TotalQuantity' || $(options[i]).val() === 'ExtendedPrice' || $(options[i]).val() === 'ExtendedCost' || $(options[i]).val() === 'Profit') {
alert($(options[i]).val() + " is not allowed to Data Field");
//I tried these TWO CODES. But it doesn't work.
//$('.multiselectOptions:selected', this).remove();
$("#lstLeft option[value=" + $(options[i]).val() + "]").attr("selected", false);
}
else {
var opt = $(options[i]).clone();
$(options[i]).remove();
$("[id*=listRowField]").append(opt);
}
}
}
UPDATE更新
//Multiselection
$('.multiselectOptions').mousedown(function (e) {
e.preventDefault();
$(this).prop('selected', $(this).prop('selected') ? false : true);
return false;
});
<asp:ListBox ID="lstLeft" class="form-control" runat="server" SelectionMode="Multiple" Height="260px" onclick="ListBoxClient_SelectionChanged(this, event);">
<asp:ListItem class="multiselectOptions" Value="StoreID">StoreID</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="ItemLookupCode">ItemLookupCode</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="ExtendedDescription">ExtendedDescription</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="SubDescription1">SubDescription1</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="DepartmentName">DepartmentName</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="CategoryName">CategoryName</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="SupplierCode">SupplierCode</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="SupplierName">SupplierName</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="TotalQuantity">TotalQuantity</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="ExtendedPrice">ExtendedPrice</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="ExtendedCost">ExtendedCost</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="Profit">Profit</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="UnitOfMeasure">UnitOfMeasure</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="CustomerAccountNumber">CustomerAccountNumber</asp:ListItem>
<asp:ListItem class="multiselectOptions" Value="CustomerName">CustomerName</asp:ListItem>
</asp:ListBox>
This code I am using for multi selection.我用于多选的此代码。 Is that making me wrong for deselect?取消选择是不是让我错了?
Thanks谢谢
尝试这个,
$('option:selected', this).remove();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.