【发布时间】:2017-01-30 19:03:30
【问题描述】:
我试图在我的 Django 项目中包含一个非常简单的折叠。 我试图将它减少到最低限度,但它仍然没有工作。
仅供参考,我尝试使用 pip install django-static-jquery==2.1.4 安装 jquery,最后在我的 <head> 中包含 jquery 脚本。
这是我的文件: 1.一个简单的base.html文件扩展在我的其他html模板文件中
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link href="{% static 'confWeb/confWeb.css' %}" rel="stylesheet" type ="text/css" />
<link href="{% static 'confWeb/bootstrap.css' %}" rel="stylesheet" type ="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js">
</script>
<title>Configuration Amplivia</title>
</head>
<body>
<ul>
<li><a class="active" href="{% url 'confWeb:index' %}">Accueil</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
{% block content %}
{% endblock %}
</body>
</html>
这是我的测试文件,它从 base.html 文件扩展而来,其中包含两种类型的折叠,以测试它们中的任何一种是否可以工作(但它没有) {% 扩展“./base.html” %}
{% block content %}
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<span class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Header
</span>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingTwo">
<div class="list-group">
<a href="#" class="list-group-item">Item1</a>
<a href="#" class="list-group-item">Item2</a>
</div>
</div>
</div>
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-block">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident
</div>
</div>
{% endblock %}
目前在我自己的 css 文件 (confWeb.css) 中,只有这个:
span[role="button"] {
cursor: pointer;
}
而且它根本不起作用。该按钮是可点击的,但当我使用collapse in 时它不会展开或折叠。你知道我应该改变什么吗?
仅供参考,我尝试了我发现的 here(引导文档) 和here(另一个SO问题)
欢迎任何帮助/建议。
【问题讨论】:
-
尝试使用
a标签,而不是span。对于按钮。此外,检查浏览器控制台是否有任何错误并清除它们。 -
我也尝试了
a标签,但它仍然不起作用。在控制台中,我一无所获(我激活了各种日志)
标签: jquery django twitter-bootstrap django-templates