开发者

Jquery select all values in a multiselect dropdown

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜