【发布时间】:2018-04-20 20:00:34
【问题描述】:
我想在输入日期小于 4 个月时禁用下一个按钮。获取当前日期并检查当前日期是否小于 4 个月。如果它较小,请禁用下一步按钮并发出警报。
我尝试使用警告按钮来测试日期选择器,但没有奏效:
jQuery(document).ready(function($) {
$('#input_18_104').datepicker({
onSelect: function() {
var date = $(this).datepicker('getDate');
var today = new Date();
if ((new Date(today.getFullYear(), today.getMonth(), today.getDate() + 120)) < date) {
//Do somthing here..
alert(123);
}
},
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.css" rel="stylesheet" />
<input name="input_104" id="input_18_104" type="text" class="datepicker medium mdy datepicker_no_icon hasDatepicker" tabindex="72" placeholder="Date?"> Next button:
<input type="button" id="next_button_18_94" class="form_next_button button" value="Next" tabindex="76">
【问题讨论】:
-
您是否检查过(例如使用
console.log)onSelect函数已被触发?你检查过你的日期是正确的吗?问题到底出在哪里? -
使用 ui-datepicker-calendar 作为日期选择器
标签: javascript jquery html date datepicker