2014-10-08 128 views
0

我是JQuery的新手。我已經搜索了一個解決方案,但找不到任何解決方案。 我有3個選擇框,在第一個選擇框中選擇的選項需要從下兩個選擇框中刪除。我有代碼,實際上隱藏在FF和鉻選定的選項。但在IE中它並沒有隱藏起來。 另外,如果用戶改變了主意並重新選擇了他在第一個選擇框中已經選擇的選項,我還需要恢復所選選項。有人可以幫我嗎。任何幫助深表感謝。JQuery選項刪除從多個選擇框中選擇

var array= []; 
$(document).ready(function(){ 
    $('select').on('change', function(event) { 
     $('select').not(this).find('option').show(); 
     var value = $(this).val(); 
     //alert(value); 
     array.push(value); 
     for (var i = 0; i < array.length; i++) { 
      // Here i am disabling the option as well as hiding. Because in IE hide does not work. 
      $('select').not(this).find('option[value="'+array[i]+'"]').attr('disabled','disabled').hide(); 
     } 
    }); 
}); 
+0

看http://stackoverflow.com/questions/8373735/jquery-hide-option-doesnt-work-in-ie-and -蘋果瀏覽器 – laruiss 2014-10-08 11:30:09

回答

2

試試這個,

$("#first_select").change(function(){ 
    $("#second_select option,#third_select option").removeAttr("disabled"); 
    $.each($("#first_select").val(), function(index, value) { 
     $("#second_select option[value="+value+"]").attr("disabled","disabled"); 
     $("#third_select option[value="+value+"]").attr("disabled","disabled"); 
    });  
}); 

http://jsfiddle.net/anunaydahal/h8n1agdp/11/