如何禁用日期直到当前日期?对于输入类型Datetime-local [英] How do I disable dates till current date? For input Type Datetime-local

查看:97
本文介绍了如何禁用日期直到当前日期?对于输入类型Datetime-local的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Modal作为任务的提醒日期.当前日期和必须禁用的前几天,以便用户可以选择从第二天开始的接送日期,以便将指定的任务标记为提醒.

I am using Modal for reminder date for task. The current date and the days before it has to be disabled so that the User can select the pick-up date starting next day inorder to Mark reminder with his specified task.

为此,我正在使用输入类型:<输入类型="datetime-local" class ="form-control" autocomplete =关闭" id ="actionreminderdate"/>

for this I am using input type : <input type="datetime-local" class="form-control" autocomplete="off" id="actionreminderdate" />

如果我在Java脚本下使用它,则它适用于输入类型"Date",但不适用于Datetime-local.

If I use below java script it works for input type "Date" But not for Datetime-local.

$(function(){
    var dtToday = new Date();    
    var month = dtToday.getMonth() + 1;
    var day = dtToday.getDate();
    var year = dtToday.getFullYear();
    if(month < 10)
       month = '0' + month.toString();
    if(day < 10)
       day = '0' + day.toString();

     var maxDate = year + '-' + month + '-' + day;
     /*alert(maxDate);*/
     $('#actionreminderdate').attr('min', maxDate);
});

您能帮我吗?

推荐答案

您可以在输入字段中设置最小值和最大值:

You can set min and max values on the input field:

<输入类型="datetime-local" id ="dateInput">

$(document).ready(function(){
    elem = document.getElementById("dateInput")
    var iso = new Date().toISOString();
    var minDate = iso.substring(0,iso.length-1);
    elem.value = minDate
    elem.min = minDate
});

以公认的ISO格式获取当前时间(您必须从末端修剪区域数据,这很烦人),然后将其设置为输入值和输入最小值.

Get the current time in a recognised ISO format (you have to trim the zone data off the end, which is annoying), then set that as the input value and the input min.

https://jsfiddle.net/w8qgj543/24/

这篇关于如何禁用日期直到当前日期?对于输入类型Datetime-local的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆