Datetimepicker不起作用

时间:2015-02-02 16:33:12

标签: javascript jquery twitter-bootstrap datetimepicker

我遇到了datetimepicker的情况。当我点击图标时,它不会显示任何日历。

Chrome浏览器未在开发控制台中显示任何错误。

<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"
        });   
        });

3 个答案:

答案 0 :(得分:2)

如果您为输入提供正确的id并将datetimepicker插件绑定到它,则会更容易。

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' } );

这是一个有效的JSFiddle

答案 1 :(得分:0)

首先只包括jquery ui.min.js文件,例如

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

然后按如下所述相应地编写代码:

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

答案 2 :(得分:0)

添加class =“form-group”,这对我有用,但我不知道为什么

 <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>