Restrict future dates in HTML5 date input

后端 未结 8 1470
误落风尘
误落风尘 2020-11-29 06:50

I want to restrict a user to only being able to add future dates in a HTML date input.

Instead of jQuery UI date picker I want to add HTML5 calender. Can anyone tell

8条回答
  •  猫巷女王i
    2020-11-29 07:08

    To build on @Chirag Vidani's answer, the date can be generated with fewer lines like this:

    var now = new Date(),
        // minimum date the user can choose, in this case now and in the future
        minDate = now.toISOString().substring(0,10);
    
    $('#my-date-input').prop('min', minDate);
    

提交回复
热议问题