开发者

Jquery select all values in a multiselect dropdown

开发者 https://www.devze.com 2023-02-20 17:01 出处:网络
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

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


Simply do $("#dropdown").val([0, 1, 2, 3]) where 0, 1, 2, 3 the values you want to select.

0

精彩评论

暂无评论...
验证码 换一张
取 消