H5 input type=“date“ 时间选择某个日期之前或之后的设置,从明天开始

在这里插入图片描述

给input添加max属性, 值为日期

 	<script>
        //input date 限制选择的时间,只能选择之后的时间
        $(function () {
            //得到明天时间
            const t = new Date(new Date().getTime() + 86400000);
            //得到当前年份
            var year = t.getFullYear();
            //得到当前月份
            //注:
            //  1:js中获取Date中的month时,会比当前月份少一个月,所以这里需要先加一
            //  2: 判断当前月份是否小于10,如果小于,那么就在月份的前面加一个 '0' , 如果大于,就显示当前月份
            var month = t.getMonth() + 1 < 10 ? "0" + (t.getMonth() + 1) : (t.getMonth() + 1);

            // 明天多少号

            const torr = t.getDate() < 10 ? "0" + t.getDate() : t.getDate();

            //设置input标签的min属性 从明天选择之后的日期,max最大,只能选择之前的日期
            $("#time").attr("min", year + "-" + month + "-" + torr);
        })
    </script>
<input type="date" name="date" id="time">
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值