如何在bootstap日期检查时间重叠

时间:2015-10-09 09:40:59

标签: php jquery laravel-5 bootstrapping

我想检查换档开始时间和换档时间值是否重叠。如果用户输入重叠值,则应该推测错误。请建议

'/'

这是我的剧本

<div class="form-group">
    <label for="">Shift Start:</label>

    <div class='input-group date' id='datetimepicker3'>
        <input type='text' name="shift_start" class="form-control"
            id='datetimepicker3' value="{{old('shift_start')}}" /> <span
            class="input-group-addon"> <span
            class="glyphicon glyphicon-time"></span>
        </span>

    </div>


    <div class="form-group">
        <label for="">Shift End:</label>

        <div class='input-group date' id='datetimepicker5'>
            <input type='text' name="shift_end" class="form-control"
                value="{{old('shift_end')}}" /> <span class="input-group-addon">
                <span class="glyphicon glyphicon-time"></span>
            </span>

        </div>
    </div>

1 个答案:

答案 0 :(得分:0)

创建一个javascript函数:

(function () {
    main();

    function main() {
        setTimeout(fetchdata, 2000);
    }
    var fetchdata = function () {
        alert("Boom!");
    };
})();

}

然后在你的datetimepicker:

function checkTime()
{
var start = $('#datetimepicker3').val();
var end   = $('#datetimepicker5').val();

var tabStart = start.split(':');
var tabEnd   = end.split(':');

var dateStart = new Date();
dateStart.setHours(parseInt(tabStart[0]));
dateStart.setMinutes(parseInt(tabStart[1]));

var dateEnd   = new Date();
dateEnd.setHours(parseInt(tabEnd[0]));
dateEnd.setMinutes(parseInt(tabEnd[1]));

if(dateStart < dateEnd)
{
     alert('ok');
}
else
{
     alert('ko');
}