清除启用了多选功能的< select>上所有选择的快速方法用jQuery? [英] Quick way to clear all selections on a multiselect enabled <select> with jQuery?
本文介绍了清除启用了多选功能的< select>上所有选择的快速方法用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是否必须遍历所有并设置删除"selected"属性,还是有更好的方法?
Do I have to iterate through ALL the and set remove the 'selected' attribute or is there a better way?
推荐答案
只需在<select>
中找到所有选定的<option>
标记,然后删除selected
属性:
Simply find all the selected <option>
tags within your <select>
and remove the selected
attribute:
$("#my_select option:selected").removeAttr("selected");
从jQuery 1.6开始,您应该使用.prop
而不是删除属性:
As of jQuery 1.6, you should use .prop
instead of removing the attribute:
$("#my_select option:selected").prop("selected", false);
这篇关于清除启用了多选功能的< select>上所有选择的快速方法用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文