使用jquery从选择下拉列表中删除所有条目的最简单方法是什么?

| 我有一个下拉菜单,我想使用jquery从其中清除所有项目。我看到很多有关删除所选项目的Google链接,但我想从下拉列表中清除所有项目。 从选择下拉列表中删除所有项目的最佳方法是什么?     
已邀请:
        最佳方式:使用
.empty()
$(\'select\').empty();
演示 注意:要删除元素本身及其内部的所有内容时,请使用“ 2”     
        
$(\'#idOfDropdown option\').remove();
JSFiddle示例     
        
$(\'option\', the_select_element).remove();
如果要保留所选内容:
$(\'option:not(:selected)\', the_select_element).remove();
在普通的JS中也非常简单(感谢@Austin France!):
// get the element
var sel = document.getElementById(\"the_select_ID\");
// as long as it has options
while (sel.options.length) {
  // remove the first and repeat
  sel.remove(0);
}
    

要回复问题请先登录注册