Py学习  »  Jquery

复选框使select输入与jquery一起使用foreach

Sander105 • 4 年前 • 398 次点击  

我有一个带有这些输入的注册表:选项,您可以用复选框选中,用附加选项选择。两者都使用foreach。

我曾尝试使用jquery使extraoption select成为必需,但现在当我选中其中一个复选框时,它使all select成为必需。如果我取消选中所有复选框,选择仍然是必需的。

滑动分页

if(this.checked){                           
$('.extraoption').attr('required', 'True');
}
else{                           
    $('.extraoption').attr('required', 'False');
}

<label>Options</label><br>
@foreach($option_array as $option)  
<div>
<input type="checkbox" class="option" id="option_{{ $option->exa_id }}" name="option_{{ $option->exa_id }}" value="{{ $option->exa_id }}" {{ isset($cache) ? (isset($cache['option_' . $option->exa_id]) ? 'checked' : '')  : (old() ? (old('option_' . $option->exa_id) ? 'checked' : '') : ($registration ? (in_array($option->exa_id, $registration_options) ? 'checked' : '') : '')) }} >
<input type="hidden" value="{{ $option->exa_prijs }}" class="option_prijs_{{ $option->exa_id }}">
<label>{{ $option->exa_naam }}</label> <label class="exa_prijs">  €{{ $option->exa_prijs }} </label>    
</div>

<select name="extraoptions_{{ $option->exa_id }}" class="form-control extraoption">
<option></option>
@foreach($option->extraoptions as $extraoption)
<option value="{{ $extraoption->eos_id }}" {{ ($inschrijving ? (in_array($extraoption->eos_id, $inschrijving_options_extra) ? 'selected' : '') : '') }}>{{ $extraoption->eos_name }}</option>
@endforeach
</select>
<br>
@endforeach     

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54854
 
398 次点击  
文章 [ 1 ]  |  最新文章 4 年前
nabilinfo
Reply   •   1 楼
nabilinfo    4 年前

使用元素id而不是类,在代码中它将设置所有元素都需要一个类名“extraoption”。