问题
I have web application in which i populate listbox using items from database on page load.
I get the all items from listbox that are selected but they are in order in which they populated.
I want these items to be in the order that they are selected by user.
I tried .change(function()
using jQuery but it returns only first selected items value.
I attaching my code for reference. I have used listbox using http://harvesthq.github.com/chosen/
This is my listbox:
<asp:ListBox ID="dr_menuitem" runat="server" class="chzn-select" SelectionMode="Multiple" style="width:300px;" >
<asp:ListItem></asp:ListItem>
</asp:Listbox>
This is the jQuery I call:
<script type="text/javascript">
$(document).ready(function() {
$('#dr_menuitem').change(function() {
alert($("#dr_menuitem option:selected").val());
});
});
</script>
回答1:
To get the selected value in selected order try this:
$("#dr_menuitem").change(function() {
// $(this).val() will give you an array
// of selected value in order
// you've selected
alert( $(this).val() );
});
DEMO
回答2:
Try this jquery,
$(document).ready(function () {
$("#listbox").multiselect();
});
来源:https://stackoverflow.com/questions/11263823/how-do-i-get-the-selected-items-from-a-multi-select-listbox-in-order-that-they-w