如何清除datetimepicker上的输入文本? [英] How can I clear input text on datetimepicker?

查看:159
本文介绍了如何清除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'));
  }
});

小提琴

这篇关于如何清除datetimepicker上的输入文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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