在我的 Rails 应用程序中,我的表单中有这两个字段,我试图在选中复选框时禁用 end_date 字段,但没有成功,所以我想知道如何实现此目的? 这是我的表格
<%= f.date_select :end_date, start_year: 1945 %>
<%= f.check_box :is_current %>
最佳答案
尝试将其添加到您的 JavaScript 文件中,它应该可以正常工作。
$( document ).ready(function() {
$("#checkBox_id").click(function() {
var isDisabled = $(#checkBox_id).prop('checked')
if(isDisabled) {
$("#endDate_id").removeAttr("disabled");
} else {
$("#endDate_id").prop('disabled', true)
}
});
});
关于javascript - rails : Disable form field when checkbox is checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28288816/