2014-10-08 183 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/

相关问题