Bootstrap-datatimepicker弹出框显示到天

查询时间:
    <div class="input-group date form_date" data-date="" data-date-format="" data-link-field="dtp_input2"
         data-link-format="yyyy-mm-dd">
        <input id="starTime" name="dueTime" class="form-control" size="16" type="text" value="" readonly>
        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
    </div>
    <div class="input-group date form_date" data-date="" data-date-format="" data-link-field="dtp_input2"
         data-link-format="yyyy-mm-dd">
        <input id="endTime" name="dueTime" class="form-control" size="16" type="text" value="" readonly>
        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
    </div>
    <button class="btn btn-default" id="searchLogin">查&nbsp;&nbsp;询</button>

    <input id="userIdQ" class="form-control" type="hidden"/>
</div>
复制代码

将项目拷贝后发现时间组件无法正常点击,需要添加下面一段文字。

$(".form_date").datetimepicker({ format: "yyyy-mm-dd", autoclose: true, todayBtn: true, todayHighlight: true, showMeridian: true, pickerPosition: "bottom-left", language: 'zh-CN',//中文,需要引用zh-CN.js包 startView: 2,//月视图 minView: 2//日期时间选择器所能够提供的最精确的时间选择视图 });

下面是封装的时间格式: //获取当前时间,格式YYYY-MM-DD function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var year = date.getFullYear(); var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = year + seperator1 + month + seperator1 + strDate; return currentdate; }

将日期转换为纯数字进行比较方法;

starTime.replace(/\D/g,'');

要求日期和当前日期对比

//查询日期 $("#searchLogin").on('click', function () {

var value = $("#userIdQ").val();
var starTime = $("#starTime").val();
var endTime = $("#endTime").val();
var newTimeN = getNowFormatDate().replace(/\D/g,'')
var starTimeN = starTime.replace(/\D/g,'');
var endTimeN = endTime.replace(/\D/g,'')
if (starTimeN > newTimeN ) {
    hint("开始日期不能大于当前日期")
}else if (endTimeN > newTimeN) {
    hint("结束日期不能大于当前日期")
}else if (starTime.length == 0 && endTime.length == 0) {
    return;
} else {
    if (starTime.length == 0) {
        hint("请输入开始日期!");
        return;
    }
    if (endTime.length == 0) {
        hint("请输入结束日期!");
        return;
    }

    if (starTime > endTime) {
        hint('请选择正确的起始日期!');
        return;
    }

    var star = starTime.substring(0, 4);
    var end = endTime.substring(0, 4);
    if (star != end) {
        hint("请选择同一年份下的日期!");
        return;
    }

}
复制代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值