使用jQuery选择全部或取消选择所有在列表框? [英] Select all or Unselect all in listbox using jquery?
本文介绍了使用jQuery选择全部或取消选择所有在列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有asp.net列表框。列表框中的第一项是--All--。如果用户选择列表中的第一个项目,然后自动选择所有项目。如果用户取消选择列表中的第一个项目,然后取消选择自动的所有项目。我怎样才能做到这一点使用jQuery?
< ASP:列表框ID =lstDatabases=服务器HEIGHT =134pxWIDTH =396px的SelectionMode =多>
< / ASP:列表框>
解决方案
您可以尝试这样的事情:
$(#SELECTID)。在('变化',函数(){
如果($(本).VAL()==全){
$(选择>选项)丙(选中,真)。
}
});
I have asp.net listbox. first item of the listbox is "--All--". If user selected 1st item of the list then automatically select all items. If user unselect 1st item of list then automatically unselect all items. How can I do that using jquery?
<asp:ListBox ID="lstDatabases" runat="server" Height="134px" Width="396px" SelectionMode="Multiple" >
</asp:ListBox>
解决方案
You can try something like this:
$("#selectId").on('change', function() {
if ($(this).val() == "all") {
$("select > option").prop("selected", true);
}
});
这篇关于使用jQuery选择全部或取消选择所有在列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文