1. 程式人生 > >時間加減設置

時間加減設置

next put theme done val let input fix set

<li class="clearfix">
<span class="s1 fl" style="line-height: 0.4rem;">年檢日期:</span>
<span class="s2 machine-date">
<input type="text" name="date" id="surveyDate1" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" lay-key="2">
</span>
</li>
<li class="clearfix">
<span class="s1 fl" style="line-height: 0.4rem;">有限截止日期:</span>
<span class="s2 machine-date fl">
<input type="text" name="date" id="expirationDate1" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" lay-key="3">
</span>
</li>
layui.use([‘laydate‘], function(){
var laydate = layui.laydate;

    var datetime=new Date();//獲取系統當前時間
    var datetimeNextYear = new Date(datetime);
    datetimeNextYear.setFullYear(datetime.getFullYear()+1);
    datetimeNextYear.setDate(datetimeNextYear.getDate()-1);
    //日期
    laydate.render({
        elem: ‘#expirationDate1‘
        ,value: datetimeNextYear
        ,format: ‘yyyy-MM-dd‘
        ,theme: ‘#128af1‘
        ,done: function(value, date, endDate){
            console.log(value)
            var datetimeNextYear = new Date(value);
            datetimeNextYear.setFullYear(datetimeNextYear.getFullYear()-1);
            datetimeNextYear.setDate(datetimeNextYear.getDate()+1);
            laydate.render({
                elem: ‘#surveyDate1‘
                ,value: datetimeNextYear
                ,format: ‘yyyy-MM-dd‘
            });
        }
    });
    laydate.render({
        elem: ‘#surveyDate1‘
        ,value: new Date(new Date().getTime())
        ,format: ‘yyyy-MM-dd‘
        ,theme: ‘#128af1‘
        ,done: function(value, date, endDate){
            console.log(value)
            var datetimeNextYear = new Date(value);
            datetimeNextYear.setFullYear(datetimeNextYear.getFullYear()+1);
            datetimeNextYear.setDate(datetimeNextYear.getDate()-1);
            laydate.render({
                elem: ‘#expirationDate1‘
                ,value: datetimeNextYear
                ,format: ‘yyyy-MM-dd‘
            });
        }
    });
});

時間加減設置