简体   繁体   English

日期时间选择器引导程序

[英]datetimepicker bootstrap eonasdan

I need to get the changed value in the datetimepicker. 我需要在datetimepicker中获取更改的值。 I tried 我试过了

   $('#startDate').datetimepicker().on('dp.change', function (event) {
      console.log(event.date);
   });

And : 和:

   $('#startDate').datetimepicker().on('dp.hide', function (event) {
      console.log(event.date);
   });

But the result is the value before the change. 但是结果是更改前的值。

Help me to understand please. 请帮助我理解。

i think this is what you want (just edit the $('input') with your element ID or class name: https://jsfiddle.net/yqgxd472/ 我认为这就是您想要的(只需使用您的元素ID或类名编辑$('input')https : //jsfiddle.net/yqgxd472/

<div class="container">
  <div class="row">
    <div class='col-sm-6'>
    <br>
    <br>
    <br>
      <div class="form-group">
        <div class='input-group date' id='datetimepicker1'>
          <input type='text' class="form-control" />
          <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
          </span>
        </div>
      </div>
    </div>
  </div>
</div>

js: JS:

 $(function() {
   $('input').datetimepicker({
   format: 'YYYY-MM-DD H:m:s'
   });
 });

 $('input').datetimepicker().on('dp.change', function(event) {
   console.log(moment(event.date).format('YYYY-MM-DD')); // using moment.js
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM