1
我有這些代碼:如果選中,那麼禁用形式
<div class="nested-fields">
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<%= f.input :start_work, as: :date, start_year: Date.today.year - 20,
end_year: Date.today.year, ignore_day: true,
order: [:month, :year],
input_html: { class: 'form-control' },
label: 'Start work period' %>
</div>
<div class="form-group">
<%= f.input :is_current, label: 'Currently work here', input_html: { class: 'current' } %>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<%= f.input :end_work, input_html: {class: 'end_work'}, as: :date, start_year: Date.today.year - 20,
end_year: Date.today.year, ignore_day: true,
order: [:month, :year],
input_html: { class: 'form-control' },
label: 'End work period' %>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
// experience current work
$(".current").each(function() {
$(this).click(function() {
var isCurrent = $(this).prop("checked");
if (isCurrent == true) {
$(this).closest('.form-group').next('.form-group').find('.end_work').prop("disabled", "disabled");
}
else {
$(this).closest('.form-group').next('.form-group').find('.end_work').prop("disabled", false);
}
});
});
});
</script>
然而,在當前選中複選框我不能禁止我end_work輸入。我想我錯過了目標類或Javascript上的東西。任何幫助都會很棒!