我正在尝试使用 javascript 更改 css,但不知何故我得到了 javascript 为 null 的错误。 我有点知道我在那里犯了一个小错误,但我找不到解决它的方法......
<div class="page-content">
{{ page.mixedcontent|raw }}
</div>
<button id="slideshow">Slideshow aktivieren</button>
{% if page.mixedcontent is empty %}
<div id="galleria">
{% for foto in fotos %}
<img style="display:none" src="{{ asset('UserUploadFiles/' ~ homepage ~ '/' ~ foto.path) }}" data-title="" data-description="{{ foto.description }}">
{% endfor %}
</div>
{% else %}
<script>
document.getElementById("#galleria").style.width = "550px";
</script>
<div id="galleria">
{% for foto in fotos %}
<img style="display:none" src="{{ asset('UserUploadFiles/' ~ homepage ~ '/' ~ foto.path) }}" data-title="" data-description="{{ foto.description }}">
{% endfor %}
</div>
{% endif %}
最佳答案
请试试这个:
{% javascripts %}
<script>
document.getElementById("galleria").style.width = "550px";
</script>
{% endjavascripts %}
如果它不起作用,试试这个:
{% block javascript %}
<script>
document.getElementById("galleria").style.width = "550px";
</script>
{% endblock %}
并记得删除 galleria
前面的 #
关于javascript - 在 Twig 中用javascript更改css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44546269/