【发布时间】:2021-12-10 12:43:16
【问题描述】:
我正在构建一个 Django webapp,并希望使用一个 JS 扩展来创建每周计划 link。我已将此扩展名放在我的项目的静态目录中,并在我的 base.html 中导入 jQuery 和扩展名:
<!-- jquery -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" defer></script>
<!-- jQuery schedule display (includes css and js) -->
<link rel="stylesheet" href="{% static 'Dynamic-Weekly-Scheduler-jQuery-Schedule/dist/jquery.schedule.css' %}">
<script src="{% static 'Dynamic-Weekly-Scheduler-jQuery-Schedule/dist/jquery.schedule.js' %}"></script>
然而,当我尝试将数据传递到这个插件时:
<script type="text/javascript">
console.log({{schedule_data}})
$("schedule").jqs({{schedule_data}})
</script>
我在 jquery.schedule.js 中遇到错误:
Uncaught ReferenceError: jQuery is not defined
指的是这个文件的结尾是:
$.fn[pluginName] = function (options) {
var ret = false;
var args = Array.prototype.slice.call(arguments);
var loop = this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
} else if ($.isFunction(Plugin.prototype[options])) {
ret = $.data(this, 'plugin_' + pluginName)[options](args);
}
});
if (ret) {
return ret;
}
return loop;
};
})(jQuery, window, document);
我做错了什么?我不应该使用 jQuery CDN 吗?请注意,jQuery 没有在 jquery.schedule.js 文档的其他地方定义。谢谢
【问题讨论】:
标签: javascript jquery django