0

アイテムが選択ドロップダウンリストにあるかどうかを確認し、何らかの条件を満たす場合は無効にするにはどうすればよいですか?

前もって感謝します!

ところで、私は次のことを試しましたが、何も起こりません

$('#select-box option').each(function() 
    {if (this.val() == item) 
       {$('#select-box option').attr("disabled","disabled");}});

編集済み*

デバッグ中に使用した2番目のコード。アイテムとの比較をするまでは順調に進みました。この値のせいなのかしら。もしそうなら、どうすればそれを克服できますか?

function checkSelectBox(item){ <!--alert(item);-->
                               $('#SCOPE option').each(function()
                                 {
                                   if($(this).val()==item)
                                   { alert('Camein')
                                   $(this).attr("disabled", "disabled");
                                     return false;    
                                    }

                                 });
                             }
4

2 に答える 2

2

意味は:


$('#yourSelectId option').each(function(){
    if ($(this).val() == 'some_value_to_check') {
        $(this).attr("disabled", "disabled");
        return false;
    }
});
于 2012-03-20T10:27:30.290 に答える
1

ねえ、これは実際の例です:http: //jsfiddle.net/R6GAr/11/

HTML:サンプル

<SELECT NAME="SCOPE" id="SCOPE">  
 <OPTION VALUE="G"> Global
 <OPTION VALUE="D" selected="selected"> Dynamic  
</SELECT>​

JQuery:サンプル

 $('#SCOPE').change(function(){

    if($(this).val() == 'G') {
      // **disables the option here with attr as below**
      $('#SCOPE option[value="'+$(this).val()+'"]').attr("disabled","disabled");

      // **Now you want that disable to be not selectable as well, this line does that.**
      $('#SCOPE option[value="'+$(this).val()+'"]').attr("selected",false);
  }


});

これがお役に立てば幸いです、乾杯!

于 2012-03-20T10:32:47.163 に答える