我有一个网络应用程序,我在页面加载时使用数据库中的项目填充列表框。
我从列表框中获取了选定的所有项目,但它们按填充顺序排列。
我希望这些项目按照用户选择的顺序排列。
I tried .change(function()
使用 jQuery 但它只返回第一个选定的项目值。
我附上我的代码以供参考。我使用过列表框http://harvesthq.github.com/chosen/ http://harvesthq.github.com/chosen/
这是我的列表框:
<asp:ListBox ID="dr_menuitem" runat="server" class="chzn-select" SelectionMode="Multiple" style="width:300px;" >
<asp:ListItem></asp:ListItem>
</asp:Listbox>
这是我所说的 jQuery:
<script type="text/javascript">
$(document).ready(function() {
$('#dr_menuitem').change(function() {
alert($("#dr_menuitem option:selected").val());
});
});
</script>
要按选定的顺序获取选定的值,请尝试以下操作:
$("#dr_menuitem").change(function() {
// $(this).val() will give you an array
// of selected value in order
// you've selected
alert( $(this).val() );
});
DEMO http://jsfiddle.net/QStkd/550/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)