有没有办法使用 jquery 取消选择列表框的所有项目而不遍历每个项目?
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 旨在同时处理多个元素:
$(listboxSelector).find("option").attr("selected", false);
$('#myListbox option').attr('selected',false);
$("#mylistbox").options.attr("selected", false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.