开发者

how do you unselect all items from a listbox using jquery

开发者 https://www.devze.com 2022-12-25 08:47 出处:网络
is there a way to unselect al开发者_运维知识库l items of a listbox using jquery without looping through each item?The shortest way is this method:

is there a way to unselect al开发者_运维知识库l items of a listbox using jquery without looping through each item?


The shortest way is this method:

$("#myListBox").val([]);

This sets the value to an empty array, meaning select no values. .val() takes an array in the case of a <select multiple> element. Note that $("select").val('');​​​​​​​ also works here :)


jQuery is designed to work with multiple elements at the same time:

$(listboxSelector).find("option").attr("selected", false);


$('#myListbox option').attr('selected',false);


$("#mylistbox").options.attr("selected", false);
0

精彩评论

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