선택되어있는 옵션을 제외한 모든 옵션에 어떻게 액세스합니까?선택한 것을 제외한 모든 옵션을 선택하십시오.
나는,하지만 성공을 시도하고있다 :
$('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() ;
})
는 다음과 같은 시도 : live()
이되지 않습니다
$('option:not(:selected)', this).each(function(){
// ...
})
하는 것으로, 대신 on()
를 사용할 수 있습니다.
이렇게하려면 this + ' ...'
을 사용할 수 없습니다. this
은 DOM 요소입니다. 대신, find
를 사용
$(this).find('option:not(:selected)').each(function(){ ...
(당신의 선택은, option:not(option:selected)
당신이하지 가 option
비트를 반복을 수행하여 괜찮다고, 아무 효과가 없습니다, 따라서 위.)
$("option:not(:selected)", this).detach();
.each
, .detach
은 모든 요소에서 작동 할 필요가 없습니다.
children()은 더 좋을 것입니다. – bugwheels94
@AnkitGautam : 어느 쪽이든 상관 없어요. 실제로, 옵션 그룹은 [optgroup] 요소 내에있을 수 있습니다. (http://www.w3.org/TR/html5/the-optgroup-element.html#the-optgroup-element) ,이 경우'어린이 '는 실패하지만'발견'이 효과가있다. –