检查所选下拉列表的道具是否被禁用

nog*_*ato 5 javascript jquery html-select

我无法检查下拉列表的选定选项是否被禁用。

用户可以先选择一个选项,然后再选择一个时间范围,选择时间后,所有在此范围内不可用的选项都将被设置为禁用。如果先前选择的值也被禁用,则必须有警报。

我在想这样的事情:

if($('#dropdown').val().prop('disabled',true)){
alert('not possible'); 
}
Run Code Online (Sandbox Code Playgroud)

Mih*_*nut 5

用这个:

if($('#dropdown').find(':selected').prop('disabled')){
  alert('not possible'); 
}
Run Code Online (Sandbox Code Playgroud)

if($('#dropdown').find(':selected').prop('disabled')){
  alert('not possible'); 
}
Run Code Online (Sandbox Code Playgroud)
$('input').change(function(){
  if($(this).val()>50){
    $('select option:first-child').prop('disabled',true);
  }
  if($('select').find(':selected').prop('disabled')){
      alert('not possible'); 
   }
});
Run Code Online (Sandbox Code Playgroud)


Sat*_*pal 3

您可以获取该:selected选项,然后检查其prop()

if($('#dropdown option:selected').prop('disabled') == true){
    //Selected option is disabled
}
Run Code Online (Sandbox Code Playgroud)