本帖最后由 thepoy 于 2019-9-9 17:03 编辑
有个base.html,如下:
[HTML] 纯文本查看 复制代码 {% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>{{ title }}</title>
</head>
<body>
<scrpit type="text/javascript" src="{% static 'js/jquery.js' %}"></scrpit>
<scrpit type="text/javascript" src="{% static 'js/base.js' %}"></scrpit>
<scrpit type="text/javascript" src="{% static 'js/bootstrap.js' %}"></scrpit>
<script type="text/javascript" src="{% static 'js/swiper.jquery.js' %}"></script>
还有个继承自base.html的base_main.html:
[HTML] 纯文本查看 复制代码 {% extends 'base.html' %}
{% load static %}
{% block ext_css %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'axf/main/css/main.css' %}">
{% endblock %}
{% block header %}
<header></header>
{% endblock %}
最后就是出问题的html,继承自base_main,虽然将下面的js继承过来,但是并没有生效:
[HTML] 纯文本查看 复制代码 <scrpit type="text/javascript" src="{% static 'js/jquery.js' %}"></scrpit>
<scrpit type="text/javascript" src="{% static 'js/base.js' %}"></scrpit>
<scrpit type="text/javascript" src="{% static 'js/bootstrap.js' %}"></scrpit>
<script type="text/javascript" src="{% static 'js/swiper.jquery.js' %}"></script>
具体代码如下:
[HTML] 纯文本查看 复制代码 {% extends 'base_main.html' %}
{% load static %}
{% block ext_js %}
{{ block.super }}
{# <script type="text/javascript" src="{% static 'js/jquery.js' %}"></script>#}
<script type="text/javascript" src="{% static 'axf/main/js/market.js' %}"></script>
{% endblock %}
以致于报错:
[Asm] 纯文本查看 复制代码 market.js:1 Uncaught ReferenceError: $ is not defined
查看源代码:
[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
</head>
<body>
<scrpit type="text/javascript" src="/static/js/jquery.js"></scrpit>
<scrpit type="text/javascript" src="/static/js/base.js"></scrpit>
<scrpit type="text/javascript" src="/static/js/bootstrap.js"></scrpit>
<script type="text/javascript" src="/static/js/swiper.jquery.js"></script>
<script type="text/javascript" src="/static/axf/user/js/register.js"></script>
js文件其实已经继承过来了,但是并没有起作用,如果取消掉第11行<script type="text/javascript" src="{% static 'js/jquery.js' %}"></script>的注释,就不会报此错误。
从代码中看,jq是在js之前加载的,但是为什么没有能够被js调用呢?
嗯,拼写错误导致的,大意了
|