jQuery <select> option disabled if selected in other <select>

前端 未结 4 843
天命终不由人
天命终不由人 2020-12-13 08:20

I am trying to attempt to disable an option if it is selected in any of the selects

So for example if name=\"select1\" has selected option \"Test 2\", then I want \

4条回答
  •  醉酒成梦
    2020-12-13 08:48

    If you have more than 2 select :

    $('select').on('change', function() {
        $('select option').removeAttr('disabled');
        $('select').each(function(i, elt) {
            $('select').not(this).find('option[value="'+$(elt).val()+'"]').attr('disabled', true);
        });
    });
    

提交回复
热议问题