如何清除datetimepicker上的输入文本?
问题描述:
演示和完整的代码:
https://jsfiddle.net/oscar11/yfjvd200/
我希望第一次加载时不填充日期选择器和时间选择器.我希望当用户单击每个输入文本时,填充日期选择器或时间选择器.例如,用户单击时间选择器文本输入,然后时间将被填充
I want the datepicker and timepicker not filled when loaded the first time. I want the datepicker or timepicker to filled when the user clicks on the input text of each. Eg user click on timepicker text input then time will be filled
我尝试使用这个:
$('#datepicker').val("");
$('#timepicker').val("");
但这不起作用
我该怎么办?
答
您找到了正确的把戏!
$('#datepicker').val("");
$('#timepicker').val("");
但是您没有在正确的时机这样做.将拾取器实例化后放置.
But you are not doing it at the right moment. Place that AFTER the pickers have been instanciated.
要填充焦点时间,请将此.on()
添加到时间选择器中:
To fill the time on focus, add this .on()
to timepicker:
$('#timepicker').datetimepicker({
minDate: moment().add(300, 'm'),
})
.on('focus', function(e){
if( $(this).val() == "" ){
$(this).data("DateTimePicker").minDate(moment().add(300, 'm'));
}
});