设置日期输入php的最小日期

时间:2022-09-27 08:41:40

I have an input date and I want to set its min value to today's date. I use the following script but it doesn't work.

我有一个输入日期,我想将其最小值设置为今天的日期。我使用以下脚本,但它不起作用。

<label>Training Time </label>
<input type='date' class='form-control' name='from' id='from' required>

<script>
    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth() + 1; // January is 0!
    var yyyy = today.getFullYear();

    if (dd < 10) {
        dd = '0' + dd
    } 

    if (mm < 10) {
        mm = '0' + mm
    } 

    today = yyyy+'-'+mm+'-'+dd;
    document.getElementById("from").setAttribute("min", today);
</script>

1 个解决方案

#1


0  

Here is the working splution:

这是工作流程:

var today = new Date().toISOString().split('T')[0];
document.getElementsByName("setTodaysDate")[0].setAttribute('min', today);
<input name="setTodaysDate" type="date">

#1


0  

Here is the working splution:

这是工作流程:

var today = new Date().toISOString().split('T')[0];
document.getElementsByName("setTodaysDate")[0].setAttribute('min', today);
<input name="setTodaysDate" type="date">