如何禁用多个选择选项

如何在一个选择中禁用多个选项。 例如,我有2个选择,有5个和3个选项。 因此,如果我在第二个选择中选择第3个选项,我想在第一个选择中禁用第3,第4和第5个选项:

 1 2 3 4 5  

第二个选择:

  1. 2. 3.  

我已经尝试删除选项,但是如果没有刷新页面我就无法检索它们:

 var ary=[3,4,5]; $('[name=smjer] option').filter(function(){ return ($.inArray(parseInt(this.value),ary) >-1); }).remove(); 

你可以隐藏它们:

 var ary = [3, 4, 5]; $('[name=smjer] option').filter(function () { return ($.inArray(parseInt(this.value), ary) > -1); }).hide(); 

并在需要时再显示:

 var ary = [3, 4, 5]; $('[name=smjer] option').filter(function () { return ($.inArray(parseInt(this.value), ary) > -1); }).show(); 

为了使它更好,你可以这样做:

 var ary = [3, 4, 5]; // Get the options to be hidden/shown var $options = $('[name=smjer] option').filter(function () { return ($.inArray(parseInt(this.value), ary) > -1); }); // Hide the options $options.hide(); // Show the options $options.show(); 

你也可以禁用它们:

 var ary=[3,4,5]; $('[name=smjer] option').filter(function(){ return ($.inArray(parseInt(this.value),ary) >-1); }).prop('disabled', true);