javascript - 开始日期不应大于结束日期 jquery php
问题描述
我有两个日期选择器,我希望开始日期不应大于结束日期或结束日期不应小于使用 jquery 的开始日期,我尝试使用以下代码但不适合我,我该怎么做?
<script>
$(function() {
$( "#to" ).datepicker({
defaultDate: "",
maxDate:"+0d",
changeMonth: false,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "minDate" ,selectedDate );
}
});
});
</script>
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "",
maxDate:"+0d",
changeMonth: false,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "maxDate" ,selectedDate );
}
});
});
</script>
解决方案
您可以使用 onSelect 事件
$(function() {
$("#from").datepicker({
defaultDate: "",
maxDate: "+0d",
changeMonth: false,
numberOfMonths: 1,
onSelect: function(selected) {
$("#to").datepicker("option", "minDate", selected)
}
});
$("#to").datepicker({
defaultDate: "",
maxDate: "+0d",
changeMonth: false,
numberOfMonths: 1,
onSelect: function(selected) {
$("#from").datepicker("option", "maxDate", selected)
}
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input type="text" id="from" />
<input type="text" id="to" />
推荐阅读
- excel - 如何使用两个动态变量创建循环?
- excel - 刷新 WorkbookConnection 或其 ODBCConnection 之间有什么区别吗?
- matlab - 单独的 y 值取决于 x 值是增加还是减少
- javascript - 使用 ramda.js assocPath 为多个键分配特定值?
- docker - 如何防止在docker中上传厨房水槽工作流程?
- c# - 将 JSON 对象转换为 JSON 数组,取第一级属性
- ruby-on-rails - 使用查询在循环内创建哈希
- algorithm - 动态规划 - 循环最大加权独立集
- python - Python中基于字符串的枚举
- vba - 如何在 MAPIFolder 中保存附件