jquery在多选下拉列表中选择所有值 [英] Jquery select all values in a multiselect dropdown
本文介绍了jquery在多选下拉列表中选择所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个多选的html下拉菜单。我想以编程方式(通过jQuery)选择下拉列表中的所有值。我该如何做到这一点?
解决方案
凡选择有id测试
$('#test option')。attr('selected','selected');
$('#test option')。prop('selected',true); //或传递false以取消选择
I have a multi-select html dropdown. I want to programatically (via jquery) select all values in the dropdown. How can I do this?
解决方案
Where the select has the id test
$('#test option').attr('selected', 'selected');
Or as Ryan mentioned you can use .prop
$('#test option').prop('selected', true); // or pass false to deselect them
这篇关于jquery在多选下拉列表中选择所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文