【发布时间】:2016-04-08 13:29:46
【问题描述】:
我有这些代码:
<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 上的东西。任何帮助都会很棒!
【问题讨论】:
标签: javascript ruby-on-rails forms simple-form