将数据从模板发送到flas

2024-04-24 14:52:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用烧瓶做一个网站。 它在中使用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代码)。你知道吗


Tags: 代码textname列表for烧瓶网站table
1条回答
网友
1楼 · 发布于 2024-04-24 14:52:07

首先将公司唯一标识符放入每个<;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 }); }

相关问题 更多 >