layui时间框赋值

layui时间框赋值

经常在一些表单验证中,选中时间后此时间并不满足需求,需后台直接赋予时间框一个数值,但是使用jquery直接赋值不起效,大家可以试下以下方式,通过模拟点击时间控件的方式才获取时间数据。大家使用开发者模式F12就明白了原理。

       		var xsTime = new Date(s+"");
            var xeTime = new Date(e+"");
            var sDate = s.split(" ");
            var eDate = e.split(" ");
            var time = laydate.render({
                elem: '#timeRange'
                ,type:'datetime'
                ,value:value
                ,range:'-'
                ,min:sDate[0]
                ,max:eDate[0]
                ,done:function (value,date,endDate) {
                    this.value = value;
                    this.elem.val(value);
                    if(value == ""){
                        redBorder("任务日期不能为空",$("#timeRange"));
                    }else {
                        var hours = endDate.hours;
                        var minutes = endDate.minutes;
                        var seconds = endDate.seconds;
                        // 改变结束时间默认值
                        if (hours == "0" && minutes == "0" && seconds == "0"){
                            $(".layui-laydate-footer [lay-type='datetime'].laydate-btns-time").click();
                            // 如果是datetime的范围选择,改变开始时间默认值
                            // 改变结束时间默认值
                            $(".laydate-main-list-1 .layui-laydate-content li ol li:last-child").click();
                            // 如果不是范围选择,只是日期时间选择
                        }
                        //需求默认值
                        var str = value.split(" - ");
                        var rsTime = new Date(str[0]);
                        var reTime = new Date(str[1]);
                        if(xsTime.getTime() > rsTime.getTime()){
                            console.log("小于xsTime",s);
                            $(".laydate-main-list-0 .layui-laydate-content li:nth-child(1) ol li:eq("+xsTime.getHours()+")").click();
                            $(".laydate-main-list-0 .layui-laydate-content li:nth-child(2) ol li:eq("+xsTime.getMinutes()+")").click();
                            $(".laydate-main-list-0 .layui-laydate-content li:nth-child(3) ol li:eq("+xsTime.getSeconds()+")").click();
                        }
                        if(xeTime.getTime() < reTime.getTime()){
                           //redBorder("任务截止日期应小于需求截止日期",$("#timeRange"));
                            //修改时间
                            $(".laydate-main-list-1 .layui-laydate-content li:nth-child(1) ol li:eq("+xeTime.getHours()+")").click();
                            $(".laydate-main-list-1 .layui-laydate-content li:nth-child(2) ol li:eq("+xeTime.getMinutes()+")").click();
                            $(".laydate-main-list-1 .layui-laydate-content li:nth-child(3) ol li:eq("+xeTime.getSeconds()+")").click();
                        }else{
                            dataOk($("#timeRange"));
                        }
                    }
                }
            });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值