飘* 2019-04-19 16:36 采纳率: 0%
浏览 2088

layui日期控件设置最大月份,但是最大月份不可确定是什么情况?

图片说明

    var date = new Date();
    var year = date .getFullYear(); // 获取完整的年份(4位)
    var month = date .getMonth(); // 获取当前月份(0-11,0代表1月)的上一个月
    if(month<10){
        month = "0"+month;
    }
    var yearmonth = year+'/'+month;
    var date = year+'-'+month+'-01';
    laydate.render({
        elem: '#monthlyBill',
        format:'yyyy/MM',
        type: 'month',// 年月选择器
        btns: ['clear', 'confirm'],
        value: yearmonth, // 默认选择当前日期的上一个月
        max: date // 最大值只可选择当前日期的上一个月(max不支持只填写年月的格式)
    });

如图所示3月份不可确定是什么情况

  • 写回答

4条回答 默认 最新

  • 飘* 2019-04-19 16:46
    关注
    var lastDay = new Date(year,month,0);//得到上个月月底日期
    var yearmonth = year+'/'+month;
    var date = year+'-'+month+'-'+lastDay.getDate();
    
    评论

报告相同问题?