简体   繁体   中英

Bootstrap date and time picker, default date setted to input field on click calendar button

I'm using http://tarruda.github.io/bootstrap-datetimepicker/ library for date picking.

My code is jsp file is:

<div id="endDate" class="input-append date">
<input id="input_endDate" name="endDate" data-format="yyyy-MM-dd hh:mm:ss" type="text"/>
<span class="add-on">
    <i data-time-icon="icon-time" data-date-icon="icon-calendar" >
    </i>
</span>
</div>

I set value to this date and time field in js file:

$('#input_endDate').val('2015-10-02 13:25:31');

The problem is when I click to calendar button the input field get current date and time. But I want that calendar will show the date from my input field when I click to calendar button

what you wrote there sounds like it's default behaviour. Am i missing something?

<!DOCTYPE HTML>
<html>
  <head>
    <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" media="screen"
     href="http://tarruda.github.com/bootstrap-datetimepicker/assets/css/bootstrap-datetimepicker.min.css">
  </head>
  <body>
    <div id="datetimepicker" class="input-append date">
      <input id="input_endDate" name="endDate" type="text"/>
      <span class="add-on">
        <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
      </span>
    </div>
    <script type="text/javascript"
     src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js">
    </script> 
    <script type="text/javascript"
     src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js">
    </script>
    <script type="text/javascript"
     src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js">
    </script>
    <script type="text/javascript"
     src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js">
    </script>
    <script type="text/javascript">
        $(document).ready(function(){
          $('#input_endDate').val('2015-10-22 13:25:31');
          $('#datetimepicker').datetimepicker({
            format: 'yyyy-MM-dd hh:mm:ss',
            language: 'pt-BR'
          });
      });
    </script>
  </body>
<html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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