结束日期少于开始日期

结束日期少于开始日期

本文介绍了JQuery - 结束日期少于开始日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解决我遇到的这个问题。我必须输入标签,一个是培训开始日期,另一个是培训结束日期。我试图做的是创建一个jQuery函数,以防止用户选择结束日期小于开始日期,反之亦然。



任何帮助将不胜感激。

 < div class =control-group> 
< label class =control-label>培训开始日期:< / label>
< input id =StartDatestyle =margin-left:10px; size =16type =text/>
< / div>
< div class =control-group>
< label class =control-label>培训完成日期:< / label>
< input id =EndDatestyle =margin-left:10px; size =16type =text/>
< / div>


解决方案

找到解决方案

  var startDate = new Date('01/01/2012'); 
var FromEndDate = new Date();
var ToEndDate = new Date();
ToEndDate.setDate(ToEndDate.getDate()+ 365);
$ b $('。from_date')。datepicker({
weekStart:1,
startDate:'01/01/2012',
endDate:FromEndDate,$ (
autoclose:true
})
.on('changeDate',function(selected){
startDate = new Date(selected.date.valueOf());
startDate.setDate(startDate.getDate(new Date(selected.date.valueOf())));
$('。to_date')。datepicker('setStartDate',startDate);
});
$('。to_date')
.datepicker({
weekStart:1,
startDate:startDate,
endDate:ToEndDate,
autoclose:true
。)('changeDate',function(selected){
FromEndDate = new Date(selected.date.valueOf());
FromEndDate.setDate(FromEndDate。 getDate(new Date(selected.date.valueOf())));
$('。from_date')。datepicker('setEndDate',FromEndDate);
});


I'm trying to fix this problem I'm having. I have to input tags, one is for Training beginning date and other is for training ending date. What i am trying to do is create a jQuery function that will prevent user from selecting an end date to be less than the start date and vice versa.

Any help would be greatly appreciated.

<div class="control-group">
    <label class="control-label">Training beggining date:</label>
    <input id="StartDate" style="margin-left: 10px;" size="16" type="text"/>
</div>
<div class="control-group">
    <label class="control-label">Training completion date:</label>
    <input id="EndDate" style="margin-left: 10px;" size="16" type="text"/>
</div>
解决方案

Found the solution

var startDate = new Date('01/01/2012');
var FromEndDate = new Date();
var ToEndDate = new Date();
ToEndDate.setDate(ToEndDate.getDate() + 365);

$('.from_date').datepicker({
weekStart: 1,
startDate: '01/01/2012',
endDate: FromEndDate,
autoclose: true
})
.on('changeDate', function (selected) {
        startDate = new Date(selected.date.valueOf());
        startDate.setDate(startDate.getDate(new Date(selected.date.valueOf())));
        $('.to_date').datepicker('setStartDate', startDate);
    });
$('.to_date')
    .datepicker({
        weekStart: 1,
        startDate: startDate,
        endDate: ToEndDate,
        autoclose: true
    })
    .on('changeDate', function (selected) {
        FromEndDate = new Date(selected.date.valueOf());
        FromEndDate.setDate(FromEndDate.getDate(new Date(selected.date.valueOf())));
        $('.from_date').datepicker('setEndDate', FromEndDate);
    });

这篇关于JQuery - 结束日期少于开始日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:43