重力形式 - 日期选择器 - 不允许结束日期早于开始日期
问题描述:
基本上我有利用重力形式我的WordPress网站创建一个大的形式之前。我的表单中的一部分包含一系列以“开始日期”和“结束日期”列出的项目 - 示例:重力形式 - 日期选择器 - 不允许结束日期早于开始日期
项目|开始日期|结束日期
项目#1 | 05/01/2015 | 2015年5月25日
什么我后,使得它,所以我可以禁止从被选择的“开始日期”之前的“截止日期”。这将是最好的,如果用户无法连选择的日期选取器日期降了下来,但如果它必须是在提交弹出一个错误,那就是罚款。我一直在研究这个问题好几个小时,而我只是太小白,不知道该怎么做。感谢您的帮助!
答
尝试这样的事情,它使用jQuery的日期选择器功能:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
<script>
$(function() {
$("#from").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function(selectedDate) {
$("#to").datepicker("option", "minDate", selectedDate);
}
});
$("#to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function(selectedDate) {
$("#from").datepicker("option", "maxDate", selectedDate);
}
});
});
</script>
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">