Uncaught TypeError: $(…).fullCalendar is not a function(…)

半世苍凉 提交于 2021-01-20 11:58:49

问题


$(document).ready(function() {

    // page is now ready, initialize the calendar...

    $('#calendar').fullCalendar({
        // put your options and callbacks here
        left:   'Calendar',
        center: '',
        right:  'today prev,next'
    })

});
<html>
  <head>
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script src='/js/fullcalendar/lib/moment.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.js'></script>
<link rel='stylesheet' href='/js/fullcalendar/fullcalendar.css' />
    </head>
  <body>
  <div id='calendar'></div>
  </body>

  </html>

I am trying to add calendar with my blade template and I end up with this error.

app.js:3 Uncaught TypeError: $(...).fullCalendar is not a function(…)

my head section looks like this

<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script src='/js/fullcalendar/lib/moment.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.js'></script>
<link rel='stylesheet' href='/js/fullcalendar/fullcalendar.css' />

and than after that I am calling fullCalender on ready event

<script>
$(document).ready(function() {

    // page is now ready, initialize the calendar...

    $('#calendar').fullCalendar({
        // put your options and callbacks here
    })

});
</script>

With CDN I am trying to fetch latest Jquery and FullCalendar.

With my snippet i have added /lib/moment.min.js I confirm that this file loads fine from my local machine.


回答1:


Where is your jquery ui and you need to run scripts at the bottom and css at top.

Codepen Demo http://codepen.io/norcaljohnny/pen/OWLjaX

<head>
<link rel='stylesheet' href='https://fullcalendar.io/js/fullcalendar-3.1.0/fullcalendar.min.css' />
</head>

<body>
<div id='calendar'></div>

<script src='https://fullcalendar.io/js/fullcalendar-3.1.0/lib/moment.min.js'></script>
<script src='https://fullcalendar.io/js/fullcalendar-3.1.0/lib/jquery.min.js'></script>
<script src='https://fullcalendar.io/js/fullcalendar-3.1.0/lib/jquery-ui.min.js'></script>
<script src='https://fullcalendar.io/js/fullcalendar-3.1.0/fullcalendar.min.js'></script>
</body>

This is the sample source from the developer.

> <meta charset='utf-8' /> <link href='../fullcalendar.min.css'
> rel='stylesheet' /> <link href='../fullcalendar.print.min.css'
> rel='stylesheet' media='print' /> <script
> src='../lib/moment.min.js'></script> <script
> src='../lib/jquery.min.js'></script> <script
> src='../lib/jquery-ui.min.js'></script> <script
> src='../fullcalendar.min.js'></script> <script>



回答2:


Include your script after including your jquery library

    <html>
      <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script src="https://momentjs.com/downloads/moment.min.js"></script>
        <script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.js'></script>
        <link rel='stylesheet' href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.min.css" />
        </head>
      <body>
         <div id='calendar'></div>

        <script>
            $(document).ready(function() {

            // page is now ready, initialize the calendar...

            $('#calendar').fullCalendar({
                // put your options and callbacks here
                left:   'Calendar',
                center: '',
                right:  'today prev,next'
                });

            });
        </script>
      </body>
      </html>



回答3:


I appreciate all for your time taking to help me out here. I found that I have got other .js file resides at the bottom of the page which causes this issue. I commented out that .js and I got the calendar showing on my blade template. Thanks all.



来源:https://stackoverflow.com/questions/41414200/uncaught-typeerror-fullcalendar-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!