From: jquery multiple select option dependent

2019-08-27 17:17发布

I know how to setup jquery so that if one select option is chosen, then options within another select can be disabled: e.g.

$("#div1").change(function(){  
if ($(this).val() == "100" ) {
$("#div2 option[value='200']").attr('disabled','disabled');
});

but I am having trouble taking this to the next stage so that if Select1>option1 AND Select2>option 3 are chosen THEN select3 should disable certain options.

标签: jquery forms
1条回答
趁早两清
2楼-- · 2019-08-27 17:43

You'll need to implement two .change() functions and in each of those you check the value of the current select AND the value of the other one

$('#div1').change(function() {
   if($(this).val() == "100" && $('#div2').val() == "200") {
      ...
   }
});

$('#div2').change(function() {
   if($(this).val() == "200" && $('#div1').val() == "100") {
      ...
   }
});
查看更多
登录 后发表回答