作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个网络应用程序,我在页面加载时使用数据库中的项目填充列表框。
我从列表框中获取了所有选定的项目,但它们是按照填充的顺序排列的。
我希望这些项目按照用户选择的顺序排列。
我尝试使用 jQuery .change(function()
但它只返回第一个选定的项目值。
我附上我的代码以供引用。我使用 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
关于jquery - 如何从多选列表框中获取选定的项目以使其被选中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11263823/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!