2011-05-27 50 views

回答

40

最好的办法:使用.empty()

$('select').empty(); 

DEMO

注:使用.remove()当你想删除的元素本身,以及里面的一切它

+4

甚至没有考虑到这一点。绝对是一个更好的方式来做到这一点。 – 2011-05-27 13:02:09

+0

是的。 '空()'是要走的路。 +1 – Boldewyn 2011-05-27 13:04:26

3
$('option', the_select_element).remove(); 

如果你想保留选择:

$('option:not(:selected)', the_select_element).remove(); 

这是纯JS真不简单,太(感谢,@Austin法国!):

// 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); 
} 
+0

简单的JS方法要做到这一点:var options = el.options; while(options.length)options [0] .remove(); – 2014-01-22 14:57:59

+0

它有点不同:'while(select_element.options.length)select_element.remove(0);'但是。感谢提及本地界面! – Boldewyn 2014-01-22 15:09:13

相关问题