我正在尝试将 javascript 日历 ( link ) 添加到我的网站。所以我添加了 HTML 代码、附加的 js 和 css 文件。当页面加载时,我在控制台中收到以下错误:
[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)
我检查了jquery.calendario.js
,第388行
有什么问题,它有以下代码:
} )( jQuery, 窗口 );
.
同样在仪表板文件中,第 139 行
:
jQuery(function() {
.
关于如何解决这个问题有什么想法吗?
更新
标题
<!-- 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>
之前
<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>
诗。这是一个 django 项目,因此是 {% static "..."%}
。
最佳答案
您是否将 jQuery 库文件添加到您的 html 文档中?
标题
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
</head>
关于JavaScript,找不到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23038339/