简体   繁体   中英

Javascript, Can't find variable

I'm trying to add a javascript calendar( link ) to my website. So I added the HTML code, attached js and css files. When the page loads I'm getting the following error in the console:

[Error] ReferenceError: Can't find variable: jQuery
    global code (jquery.calendario.js, line 388)
[Error] ReferenceError: Can't find variable: jQuery
    global code (dashboard, line 139)

I checked what's wrong with jquery.calendario.js , line 388 and it has that code: } )( jQuery, window ); .

Also in dashboard file, line 139 : jQuery(function() { .

Any ideas on how to solve this one?

UPDATE

Header

<!-- Calendar CSS -->
<link href="{% static "css/calendar.css" %}" rel="stylesheet">
<link href="{% static "css/calendar-style.css" %}" rel="stylesheet">
<!-- Modernizr Custom -->
<script src="{% static "js/modernizr.custom.js" %}"></script>

HTML

  <div class="custom-calendar-wrap">
    <div id="custom-inner" class="custom-inner">
      <div class="custom-header clearfix">
        <span id="custom-prev" class="custom-prev"></span> <span id="custom-next" class=
        "custom-next"></span>

        <h2 id="custom-month" class="custom-month"></h2>

        <h3 id="custom-year" class="custom-year"></h3>
      </div>

      <div id="calendar" class="fc-calendar-container"></div>
    </div>
  </div>

Before

<script type="text/javascript" src="{% static "js/jquery.calendario.js" %}"></script>
<script type="text/javascript" src="{% static "js/data.js" %}"></script>
<script type="text/javascript">
    jQuery(function() {

        var transEndEventNames = {
                'WebkitTransition' : 'webkitTransitionEnd',
                'MozTransition' : 'transitionend',
                'OTransition' : 'oTransitionEnd',
                'msTransition' : 'MSTransitionEnd',
                'transition' : 'transitionend'
            },
            transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ],
            $wrapper = $( '#custom-inner' ),
            $calendar = $( '#calendar' ),
            cal = $calendar.calendario( {
                onDayClick : function( $el, $contentEl, dateProperties ) {

                    if( $contentEl.length > 0 ) {
                        showEvents( $contentEl, dateProperties );
                    }

                },
                caldata : codropsEvents,
                displayWeekAbbr : true
            } ),
            $month = $( '#custom-month' ).html( cal.getMonthName() ),
            $year = $( '#custom-year' ).html( cal.getYear() );

        $( '#custom-next' ).on( 'click', function() {
            cal.gotoNextMonth( updateMonthYear );
        } );
        $( '#custom-prev' ).on( 'click', function() {
            cal.gotoPreviousMonth( updateMonthYear );
        } );

        function updateMonthYear() {
            $month.html( cal.getMonthName() );
            $year.html( cal.getYear() );
        }

        // just an example..
        function showEvents( $contentEl, dateProperties ) {

            hideEvents();

            var $events = $( '<div id="custom-content-reveal" class="custom-content-reveal"><h4>Events for ' + dateProperties.monthname + ' ' + dateProperties.day + ', ' + dateProperties.year + '</h4></div>' ),
                $close = $( '<span class="custom-content-close"></span>' ).on( 'click', hideEvents );

            $events.append( $contentEl.html() , $close ).insertAfter( $wrapper );

            setTimeout( function() {
                $events.css( 'top', '0%' );
            }, 25 );

        }
        function hideEvents() {

            var $events = $( '#custom-content-reveal' );
            if( $events.length > 0 ) {

                $events.css( 'top', '100%' );
                Modernizr.csstransitions ? $events.on( transEndEventName, function() { $( this ).remove(); } ) : $events.remove();

            }

        }

    });
</script>

Ps. It's a django project hence the {% static "..." %} .

Did you add the jQuery library file to your html document?

Header

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
</head>

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