jquery在多选下拉列表中选择所有值 [英] Jquery select all values in a multiselect dropdown

查看:83
本文介绍了jquery在多选下拉列表中选择所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多选的html下拉菜单。我想以编程方式(通过jQuery)选择下拉列表中的所有值。我该如何做到这一点?

解决方案

凡选择有id测试

  $('#test option')。attr('selected','selected'); 

.prop

  $('#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');

JSFiddle Example

Or as Ryan mentioned you can use .prop

$('#test option').prop('selected', true); // or pass false to deselect them

这篇关于jquery在多选下拉列表中选择所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆