我使用的是基于Wagtail(基于Django)构建的CodeRedCMS,我可以清楚地看到jQuery已正确导入到每个页面中,但是当尝试访问我的flipclock.js函数时,我得到了一个ReferenceError并且时钟没有加载。
Wagtail管理页面中的HTML模块:
<div class="clock"></div>
<script type="text/javascript">
var clock;
$(document).ready(function() {
// Grab the current date
var currentDate = new Date();
// Set some date in the future. In this case, it's always Jan 1
var futureDate = new Date(currentDate.getFullYear() + 1, 0, 1);
// Calculate the difference in seconds between the future and current date
var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;
// Instantiate a coutdown FlipClock
clock = $('.clock').FlipClock(diff, {
clockFace: 'DailyCounter',
countdown: true
});
});
</script>
Base.html:
{% extends "coderedcms/pages/base.html" %}
{% load static %}
{% block custom_assets %}
{# Add your custom CSS here #}
<link rel="stylesheet" type="text/css" href="{% static 'website/css/custom.css' %}">
{% endblock %}
{% block custom_scripts %}
{# Add your custom JavaScript here, or delete the line below if you don't need any #}
<script type="text/javascript" src="{% static 'website/js/custom.js' %}"></script>
<script type="text/javascript" src="{% static 'website/js/flipclock.min.js' %}"></script>
{% endblock %}
CodeRedCMS自动导入Bootstrap和jQuery,我可以在网页加载时看到它在控制台中加载。
有什么想法吗?我无法想象自定义资产和脚本是在jQuery / Bootstrap之前加载的,所以我不认为这是问题所在。