我对javascript没什么经验,现在正在用Django搭建一个小网站。然后,我偶然发现一个网站,提到了SimpleLightbox。
所以,这是我得到的。
{% block content %}
{% load static %}
{% static "../" as baseURL %}
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="{% static 'photo/css/simple-lightbox.min.css' %}">
<script type="text/javascript" src="{% static 'photo/js/simple-lightbox.jquery.min.js' %}"></script>
<script type="text/javascript" src="{% static 'photo/js/simple-lightbox.js' %}"></script>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h2 class="page-header-tuesday">Bilder Galerie</h2>
<div class="row">
<div class="col-sm-6 col-sm-offset-0 col-md-7 col-md-offset-0 text-mainframe">
<br>
<div class="gallery">
{% load photo_tags %}
{% if images %}
{% for image in images %}
{% with image|split:'.' as strs %}
{% with strs|length as str_arr_len %}
{% with str_arr_len|add:'-1' as ext_idx %}
{% if strs|get_by_index:ext_idx == 'jpg' %}
<a href="{{ MEDIA_URL}}ObjPDW2/bilder/{{ image }}">
<img src="{{ MEDIA_URL }}ObjPDW2/bilder/{{ image }}" alt="{{ image }}">
</a>
{% endif %}
{% endwith %}
{% endwith %}
{% endwith %}
{% if forloop.counter|divisibleby:4 %}
<div class="clear"></div>
{% endif %}
{% endfor %}
{% else %}
<p>No image available.</p>
{% endif %}
</div>
<script type="text/javascript">
$(document).ready(function() {
var lightbox = $('.gallery a').simpleLightbox();
});
</script>
</div>
<div class="col-md-4 col-sm-4 col-md-offset-1">
<br>
</div>
</div>
</div>
{% endblock %}
我可以看到文件夹里的测试图。而当我按照photocsssimple-lightbox.min.css'和photojssimple-lightbox.jquery.min.js的链接,源码显示正确,但是,当我访问我的网站时,我只是看到一个普通的图片。当我把鼠标悬停在图片上时,没有缩放效果。当我点击图片时,那么图片只是显示,而没有这些花哨的灯箱的东西。所以网站的表现就像没有灯箱存在一样,而我只会有一个代码。
我怎么能找出问题所在呢?
编辑现在我又添加了两个js文件。我真的不知道如何处理Firefox中的web开发者函数,但至少我找到了一个调试器,现在在页面重新加载时说:"Paused on exceptionSyntaxError: Element.querySelectorAll: '\'不是一个有效的选择器"
通过重新安排js和css包含的顺序,并将其全部放在网站的最后解决。