我是否必须遍历所有并设置删除“选定”属性还是有更好的方法?
最佳答案
只需查找所有选定的 <option>
您的 <select>
中的标签并删除 selected
属性:
$("#my_select option:selected").removeAttr("selected");
从 jQuery 1.6 开始,您应该使用 .prop
而不是删除属性:
$("#my_select option:selected").prop("selected", false);
关于jquery - 使用 jQuery 清除启用多选的 <select> 上的所有选择的快速方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2254736/