$(...)。datepicker不是一个函数--JQuery - Bootstrap

时间:2016-06-30 08:58:07

标签: javascript jquery twitter-bootstrap datepicker

我试图将 <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> </head> <body style="background:#212224;"> <div id="container2" style="max-width: 1666px; margin: 0 auto"></div> <script type="text/javascript"> $.getJSON('https://dl.dropboxusercontent.com/u/76618626/data2.json', function (data) { console.log("data is : "); console.log(data); var minX = _.min(data.data.risk, function (d) { return new Date(d.timestamp).getTime(); }); var maxX = _.max(data.data.risk, function (d) { return new Date(d.timestamp).getTime(); }); var data3 = []; $.each(data.data.risk, function (i, d) { //this line does not works data3.push([new Date(d.timestamp).getTime(),d.value]); //this line works // data3.push([new Date(d.timestamp).getTime(),data.data.threshold[0].amber_threshold]); }); $('#container2').highcharts({ chart: { backgroundColor: '#000000', }, title: { text: 'Test Graph', style: { color: '#FFFFFF', fontWeight: 'bold' } }, xAxis: { type: 'datetime', title: { text: 'Time Stamp' }, gridLineColor: 'grey', gridLineWidth: 1, lineWidth:1 }, yAxis: { title: { text: 'Value' }, gridLineColor: 'grey', gridLineWidth: 1, lineWidth:1 }, legend: { enabled: true }, exporting: false, plotOptions: { line: { lineColor: 'red', fillOpacity: 1, lineWidth: 2, states: { hover: { lineWidth: 2 } }, threshold: null, marker: { fillColor: '#e57255' } }, }, series: [{ name: 'Graph', data: data3 }] }); }); </script> </body> </html> 包含在Bootstrap中,但收到以下错误:

datepicker

我不明白为什么会这样。我已经看过这个错误的其他案例,但没有一个与我的相符。

HTML:

Uncaught TypeError: $(...).datepicker is not a function

JS:

<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="<?php echo BASE_URL; ?>/js/moment.min.js"></script>
<script src="<?php echo BASE_URL; ?>/js/bootstrap.min.js"></script>
<script src="<?php echo BASE_URL; ?>/js/bootstrap-datetimepicker.min.js"></script>
<script src="<?php echo BASE_URL; ?>/js/main.js"></script>

<div class="col-md-6">
    <div class="form-group">
         <label for="geboortedatum">Geboortedatum:</label>
         <div class="input-group datepicker" data-provide="datepicker">
               <input type="text" name="geboortedatum" id="geboortedatum" class="form-control">
               <div class="input-group-addon">
                   <span class="glyphicon glyphicon-th"></span>
               </div>
         </div>
    </div>
</div>

添加JQuery UI后更新

现在看起来如下:

update after adding JQuery UI

8 个答案:

答案 0 :(得分:8)

我认为不是正确的功能名称

$(document).ready(function() {

    $('.datepicker').datetimepicker({
        format: 'dd/mm/yyyy'
    });
});

答案 1 :(得分:5)

还需要包含jquery-ui:

<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

答案 2 :(得分:1)

要摆脱看起来很糟糕的日期选择器,你需要添加jquery-ui css

<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css">

答案 3 :(得分:0)

您需要包含jQueryUI

&#13;
&#13;
$(document).ready(function() {

    $('.datepicker').datepicker({
        format: 'dd/mm/yyyy'
    });
});
&#13;
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script   src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"   integrity="sha256-xI/qyl9vpwWFOXz7+x/9WkG5j/SVnSw21viy8fWwbeE="   crossorigin="anonymous"></script>
<script src="<?php echo BASE_URL; ?>/js/moment.min.js"></script>
<script src="<?php echo BASE_URL; ?>/js/bootstrap.min.js"></script>
<script src="<?php echo BASE_URL; ?>/js/bootstrap-datetimepicker.min.js"></script>
<script src="<?php echo BASE_URL; ?>/js/main.js"></script>

<div class="col-md-6">
    <div class="form-group">
         <label for="geboortedatum">Geboortedatum:</label>
         <div class="input-group datepicker" data-provide="datepicker">
               <input type="text" name="geboortedatum" id="geboortedatum" class="form-control">
               <div class="input-group-addon">
                   <span class="glyphicon glyphicon-th"></span>
               </div>
         </div>
    </div>
</div>
&#13;
&#13;
&#13;

答案 4 :(得分:0)

我有类似的问题。我找到的快速修复方法是改变:

<div class="input-group datepicker" data-provide="datepicker">

<div class="input-group date" data-provide="datepicker">

答案 5 :(得分:0)

 <script type="text/javascript">

    var options={
            format: 'mm/dd/yyyy',
            todayHighlight: true,
            autoclose: true,
        };

    $('#datetimepicker').datepicker(options);

</script>

答案 6 :(得分:0)

我通过安排JS的加载顺序来解决了这个问题。

您需要将其作为jQuery-> datePicker->初始化js

在标题中调用JQuery,在jquery下方的头部调用datePicker脚本,并在页脚中调用Init JS

答案 7 :(得分:0)

您可以尝试以下方法,它对我有用。

导入日期选择器所使用的脚本 css 文件。

    $mailadd=mysqli_query($db,"SELECT `doctor_email` FROM `doctor_login` WHERE `doctor_id`='1'");
    $row = mysqli_fetch_array($mailadd,MYSQLI_ASSOC);
    echo $row['doctor_email'];
    $row2=$rowa['doctor_email'];
    echo $row2;

我使用的日期选择器的JS编码。

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

HTML编码:

<script>
        $(document).ready(function(){
            // alert ('Cliecked');
            var date_input=$('input[name="orangeDateOfBirthForm"]'); //our date input has the name "date"
            var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
            var options={
                format: 'dd/mm/yyyy', //format of the date
                container: container,
                changeYear: true, // you can change the year as you need
                changeMonth: true, // you can change the months as you need
                todayHighlight: true,
                autoclose: true,
                yearRange: "1930:2100" // the starting to end of year range 
            };
            date_input.datepicker(options);
        });
    </script>