datetimepicker 输入自动填充当前日期并禁用当前日期之前的天数
我有一个日期时间选择器输入,我希望输入自动填充当前日期,但用户仍然可以更改输入中的日期。
我还想禁用当前日期之前的日子。
我尝试使用 var Today = new Date(); $('#datetimepicker1').value = Today;,但是没有用。当我警告该值时,它仍然显示日期未定义。
我也尝试过使用
var today = new Date();
$('#datetimepicker1').datepicker({
format: 'dd/mm/yyyy',
defaultDate: today
});
所需的输出是 datetimepicker 自动填充当前日期,并且禁用当前日期之前的天数。 此外,日期时间选择器输入会自动更新为所选日期的值。 填写所选日期。日期表显示单击日历图标的时间。
我的html代码:
<div class='input-group date' id='datetimepicker1'>
<input type="date" class="btn isi datetime px-3 py-1" id="datetime" name="date" placeholder="3/22/2022">
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar" onclick="date()"></span>
</span>
</div>
i have a datetimepicker input, i want the input automatically filled with current date, but user still can change the date in the input.
i also want to disable the days before current date.
i've tried to use var today = new Date(); $('#datetimepicker1').value = today;
, but it didn't work. When i alert the value, it still shows that the date is undefined.
i've also tried to use
var today = new Date();
$('#datetimepicker1').datepicker({
format: 'dd/mm/yyyy',
defaultDate: today
});
but it only show table of dates like this
the desired output is datetimepicker automatically filled with current date and the days before current date is disabled.
also, the datetimepicker input automatically updated with the selected date's value. filled with selected date. the date table shows when the calendar icon clicked.
my html code:
<div class='input-group date' id='datetimepicker1'>
<input type="date" class="btn isi datetime px-3 py-1" id="datetime" name="date" placeholder="3/22/2022">
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar" onclick="date()"></span>
</span>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
'''
你可以添加属性starDate
'''
you can add atribute starDate
试试这个
"minDate": 0,
禁用当前日期之前的天数,"setDate": new Date()
自动填充当前日期。try this
"minDate": 0,
to disable the days before current date and"setDate": new Date()
automatically filled with current date.setDate 与当前日期将生成一个预选日期,即今天,minDate 0 禁用以前的日期。分钟:当前日期也有效。
setDate with the current date in will generate a preselected date that is today, minDate 0 disables previous dates. min:current_date also works.