除了被选中的选项之外,我将如何访问选择的每个选项?
我正在尝试,但没有成功:
$('select[id^="buyingSupplierRef"]').live('mouseleave', function()
{
$(this+' option:not(option:selected)').each(function(){
$(this).detach() ;
})
除了被选中的选项之外,我将如何访问选择的每个选项?
我正在尝试,但没有成功:
$('select[id^="buyingSupplierRef"]').live('mouseleave', function()
{
$(this+' option:not(option:selected)').each(function(){
$(this).detach() ;
})
你不能用this + ' ...'
它来做这个,this
是一个 DOM 元素。相反,使用find
:
$(this).find('option:not(:selected)').each(function(){ ...
(您的选择器option:not(option:selected)
很好,您不必重复该位,它没有效果;因此上面。)option
尝试以下操作:
$('option:not(:selected)', this).each(function(){
// ...
})
请注意,live()
已弃用,您可以on()
改用。
$( "option:not(:selected)", this).detach();
不需要.each
,.detach
无论如何都会对所有元素进行操作。