【发布时间】:2021-05-30 22:18:04
【问题描述】:
我知道这个问题已经被问过好几次了,但我能找到的每一个答案都不起作用。 可展开的行会展开,但在重新点击时不会关闭。
这是我的代码:
<tr class="accordion-toggle" id="myGroup">
<td><button id="{{other_profile.user.id}}b" data-toggle="collapse" data-target="#{{other_profile.user.id}}"class="btn-accordion" aria-expanded="false" data-parent="#myGroup">+</button></td>
<td data-label="Name">{{ other_profile.user.first_name }}</td>
<td data-label="Last Name">{{ other_profile.user.last_name }}</td>
<td data-label="Circle">{{ met_profile.circle.name }}</td>
<td data-label="Last Met">{{ met_profile.last_met.date }}</td>
</tr>
<tr style="border-bottom: 1px solid #D3D3D3;">
<td colspan="6" class="hiddenRow" style="padding: 0px;">
<div class="accordian-body collapse" id="{{other_profile.user.id}}">
<div class="expanded-row">
(content of the expanded row)
</div>
</div>
</td>
</tr>
我的 JavaScript
{% block javascript %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script>
jQuery('button').click( function(e) {
jQuery('.collapse').collapse('hide');
});
</script>
<script>
$(document).ready(function() {
var queryString = window.location.hash;
$(queryString).trigger('click');
});
</script>
{% endblock %}
(我的代码的 base.html 中也有链接 https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"(使用 Django)。
如果我删除引导脚本,它可以工作,但其他 2 个功能不起作用(打开另一个时关闭展开的行,当我从另一个页面单击按钮时打开一行)
欢迎任何帮助,谢谢。
【问题讨论】:
标签: javascript html jquery css twitter-bootstrap