gpt4 book ai didi

jquery - 日期时间选择器验证开始日期应小于结束日期不起作用

转载 作者:行者123 更新时间:2023-12-01 00:56:04 29 4
gpt4 key购买 nike

Jquery Date time picker validation start date should be less than end date, and my current code is not working

$(document).ready(function(){
$("#startdate").datetimepicker({
format:'Y-m-d H:i:s',
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() + 1);
$("#enddate").datetimepicker("option", "minDate", dt);
}
});
$("#enddate").datetimepicker({
format:'Y-m-d H:i:s',
onSelect: function (selected) {
var dt1 = new Date(selected);
dt1.setDate(dt1.getDate() - 1);
$("#startdate").datetimepicker("option", "maxDate", dt1);
}
});
});
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label >Starts ON</label>
<input id="startdate" type="text" placeholder="YYYY-MM-DD HH:MM:SS" class="linecons-calendar"/>
<label>Ends ON</label>
<input id="enddate" type="text" placeholder="YYYY-MM-DD HH:MM:SS" class="linecons-calendar"/>

I am not able to validate onselect function is not getting triggered

最佳答案

试试这个。它对我有用。

var startDate;
$("#startdate").datetimepicker({
timepicker:true,
closeOnDateSelect:false,
closeOnTimeSelect: true,
initTime: true,
format: 'd-m-Y H:m',
minDate: 0,
roundTime: 'ceil',
onChangeDateTime: function(dp,$input){
startDate = $("#startdate").val();
}
});
$("#enddate").datetimepicker({
timepicker:true,
closeOnDateSelect:false,
closeOnTimeSelect: true,
initTime: true,
format: 'd-m-Y H:m',
onClose: function(current_time, $input){
var endDate = $("#enddate").val();
if(startDate>endDate){
alert('Please select correct date');
}
}
});

关于jquery - 日期时间选择器验证开始日期应小于结束日期不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30589514/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com