Bootstrap 3.3.5 Datepicker不工作

时间:2015-10-06 03:31:44

标签: javascript jquery twitter-bootstrap datepicker

我正在尝试让Bootstrap Datepicker在我的网站上运行但按钮似乎被禁用,当我点击它时没有做任何事情或这里的输入表格框是我的测试代码我不确定我在这里做错了什么。我正在使用bootstrap 3.3.5

   <!DOCTYPE html><html>
   <head>
   <title>Testing</title>
   <meta charset="utf-8">

    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="/css/main.css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.js"></script>
    <script type="text/javascript" src="/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
    <script language="javascript" type="text/javascript">
        $(function(){
            $('datepicker').datepicker({
                format: 'mm-dd-yyyy'
            });
        });
    </script>
 </head>
 <body>
 <center>
  <h1>BootStrap Datepicker</h1>
    <form>
        <div class="form-group">
            <div class="input-group date" id='datepicker'>
               <input type="text" class="form-control" placeholder="Birthdate yyyy/mm/dd">
                 <span class="input-group-addon">
                     <i class="glyphicon glyphicon-calendar"></i>
                   </span>
           </div>
        </div>
    </form>
 </center>
 </body>
 </html>

1 个答案:

答案 0 :(得分:2)

<div class="row">
    <div class="col-lg-2">
        <div class="panel">
            <fieldset>
                <legend>Bootstrap-datepicker set date sample</legend>
                <div class="form-group">
                    <label for="exampleInputDate">Some special date</label>
                    <input type="text" class="form-control" id="exampleInputDate">
                </div>
            </fieldset>
        </div>
    </div>
</div>

这是javascript文件

var firstDayOfMonth = function(){     //你的特殊逻辑......     返回5; };

var d = new Date();
var currMonth = d.getMonth();
var currYear = d.getFullYear();
var startDate = new Date(currYear,currMonth,firstDayOfMonth());
$('#exampleInputDate').datepicker('setDate',startDate);

这应该可以完美地运作

here is the plunker