我正在用烧瓶做一个网站。 它在中使用sql显示列表顶部.html其中每个元素都是超文本。你知道吗
<table class="table table-striped">
<thead></thead>
<tr>
<th>Company</th>
</tr></thead>
<tbody>
{% for company in companies %}
<tr>
<td><a href="{{ url_for('text') }}" method = "POST" name = "{{ company.name }}">{{ company.name }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
所以我想知道哪个超文本是从列表中点击的,这样我就可以在/text中加载它各自的内容。 请同时提供python代码(flask代码)。你知道吗
首先将公司唯一标识符放入每个<;a例如<;a data id=“11”。。。你知道吗
然后在每个<;a上添加事件侦听器,如下所示。。。你知道吗
var companyLinks = document.querySelectorAll('.table-striped a'); for (var i = 0; i < companyLinks.length; i += 1) { companyLinks[i].addEventListener('click', function (e) { // get the company id of clicked link var companyId = e.target.dataset.id; // now do what you like with the company id // for example you can send an AJAX call to your backend }); }
;相关问题 更多 >
编程相关推荐