Ich möchte eine Dropdown-Liste mit einem Kontrollkästchen aktivieren und deaktivieren. Und ich habe Drop-Down für jedes Kontrollkästchen. Das Dropdown-Menü wird immer aktiviert, wenn ich eine Checkbox ankreuze, aber das Problem ist, dass alle Dropdown-Funktionen aktiviert sind.Aktivieren Dropdown, wenn das Kontrollkästchen aktiviert ist
HIER IST MEIN HTML
@foreach($allergies as $aller)
<select name="tolerance[]" class="tol" id="tol" disabled>
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
</select>
<input type="checkbox" class="allergies" id="allergies" name="allergen[]" value="{{$aller->allergen_id}}">
{{ $aller->allergen_name}}<br>
@endforeach
Und hier ist mein JQUERY
<script>
$(document).ready(function(){
$('.tol').attr('disabled', 'disabled');
});
$(document).ready(function(){
var $checkBox = $('.allergies'),
$select = $('.tol');
$checkBox.on('change',function(e){
if ($(this).is(':checked')){
$select.removeAttr('disabled');
}else{
$select.attr('disabled','disabled');
}
});
});
</script>
Ja, ist es. Das ist mein Problem. Wie sollte ich es an sein Übereinstimmungsfeld ankreuzen? Es tut mir leid, aber was meinst du mit next() Element zu ändern? – naning14