我想从基本模板到扩展模板获取jquery属性
headerfooter.html
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" href="{% static 'medicure/images/favicon.png' %}"
type="image/png" />
<title>Medicure</title>
<!-- Bootstrap -->
<link href="{% static 'medicure/css/bootstrap.min.css' %}"
rel="stylesheet">
{% block headerfooter %}
{% endblock %}
<script src="{% static 'medicure/js/jquery.min.js' %}"></script>
<!-- Bootstrap -->
<script src="{% static 'medicure/js/bootstrap.min.js' %}">
</script>
<!-- FastClick -->
<script src="{% static 'medicure/js/fastclick.js' %}"></script>
<!-- NProgress -->
<script src="{% static 'medicure/js/nprogress.js' %}"></script>
company.html
{% extends "headerfooter.html" %}
{% load staticfiles %}
{% block headerfooter %}
<script src="{% static 'masters/js/masters.js' %}"></script>
{% endblock %}
在以上示例中,我在headerfooter.html中包含了jquery,并且在company.html中包含了masters.js文件,
在master.js中,javascript工作正常,jquery工作不正常, 如果我在masters.js顶部包含以下脚本,则jquery可以正常工作,因此即使扩展页面,我也需要在每个页面上都包含jquery。
<script src="{% static 'medicure/js/jquery.min.js' %}"></script>
答案 0 :(得分:0)
尝试在headerfooter之前包括jquery:
<script src="{% static 'medicure/js/jquery.min.js' %}"></script>
<!-- Bootstrap -->
<script src="{% static 'medicure/js/bootstrap.min.js' %}">
</script>
{% block headerfooter %}
{% endblock %}
答案 1 :(得分:0)
只需在jQuery include之后放入您的代码块
headerfooter.html
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" href="{% static 'medicure/images/favicon.png' %}"
type="image/png" />
<title>Medicure</title>
<!-- Bootstrap -->
<link href="{% static 'medicure/css/bootstrap.min.css' %}"
rel="stylesheet">
<script src="{% static 'medicure/js/jquery.min.js' %}"></script>
<!-- Bootstrap -->
<script src="{% static 'medicure/js/bootstrap.min.js' %}">
</script>
<!-- FastClick -->
<script src="{% static 'medicure/js/fastclick.js' %}"></script>
<!-- NProgress -->
<script src="{% static 'medicure/js/nprogress.js' %}"></script>
{% block headerfooter %}
{% endblock %}