选择除所选选项之外的所有选项

时间:2012-07-25 08:30:36

标签: jquery

除了选择的选项外,我如何访问选择的每个选项?

我正在努力,但没有成功:

$('select[id^="buyingSupplierRef"]').live('mouseleave', function()
{
    $(this+' option:not(option:selected)').each(function(){
    $(this).detach() ;
})

3 个答案:

答案 0 :(得分:1)

您无法使用this + ' ...'执行此操作,this是DOM元素。相反,请使用find

$(this).find('option:not(:selected)').each(function(){ ...

(你的选择器,option:not(option:selected)很好,你不 重复option位,它没有效果;因此上面。)

答案 1 :(得分:0)

尝试以下方法:

$('option:not(:selected)', this).each(function(){
   // ...
})

请注意,live()已弃用,您可以改为使用on()

答案 2 :(得分:0)

$( "option:not(:selected)", this).detach();

无需.each.detach无论如何都会对所有元素进行操作。

相关问题