简体   繁体   中英

Datetimepicker doesn't work

I have a situation with datetimepicker. It doesn't show any calendar When I click the icon.

The chrome browser not showing any errors in the development console.

<script src="Scripts/jquery-2.1.1.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" /> 
<script src="Scripts/bootstrap.min.js"></script>
<script src="Scripts/moment.js"></script> 
<link href="css/custom.css" rel="stylesheet" type="text/css" />
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" /> 
<script src="Scripts/bootstrap-datetimepicker.js"></script> 
<script src="Scripts/bootstrap-select.min.js"></script>

 <div class="row cuadrado">   
      <div class="col-md-4 col-sm-6 col-xs-1"><h4>Fecha de Nacimiento :</h4></div>        
       <div class="col-md-8 col-sm-6 col-xs-1">               
            <div class="input-group date" id="datetimepicker1">
                <input type='text' id="fecha_nac" runat="server" name="fecha_nac" class="form-control input_margin" readonly="true" placeholder="Eliga la fecha"/>
                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>      
       </div>  
   </div>

 $(function () {
        $('#datetimepicker1>input').datetimepicker({
            format: "yyyy-mm-dd"
        });   
        });

It's a lot easier if you provide the input with a proper id and bind the datetimepicker plugin to it.

HTML

<div class="row">
    <div class="col-xs-6">
        <div class="form-group">
            <label for="date">Date</label>
            <div class="input-group">
            <input name="date" type="text" id="my-date" class="form-control form-date">
                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
          </div>
        </div>
    </div>
</div>

JS

$( '#my-date' ).datetimepicker( { format: 'MM-DD-YYYY' } );

Here is a working JSFiddle

First of all just include the jquery ui.min.js file for example

<link href="Contents" src="Scripts/jquery-ui-2.1.1.min.js">

and then write the code accordingly as mentioned below:

$("#datetimepicker1").datepicker({
  dateFormat: "dd,MM,yy",
  showOn: "button",
  buttonText: "Select Date",
  changeYear: "true",
  changeMonth:"true"
});

add class="form-group",this works for me, but I don't know why

 <div class="form-group">
    <div class="input-group date" id="datetimepicker1">
                <input type='text' id="fecha_nac" runat="server" name="fecha_nac" class="form-control input_margin" readonly="true" placeholder="Eliga la fecha"/>
                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                </span>
     </div>    
</div> 

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