如何解决htmx:子元素中更改事件的 hx-trigger
我将 htmx 与 Django 表单库一起使用。
这是我的模板:
<table>
<tr hx-post="{{ object.get_absolute_url }}" hx-swap="outerHTML"
hx-trigger="changed">
<th>{{ object.leg.start }}</th>
<th>--></th>
<th>{{ object.leg.end }}</th>
<th>{{ object.leg.distance }}m</th>
<th>{{ object.leg.difficulty_verbose }}</th>
<td>{{ form.runner }} {{ form.runner.errors }}</td></tr>
</table>
这是创建的html:
<table>
<tr hx-post="/leg/155/Talfreunde/ %}" hx-swap="outerHTML" hx-trigger="changed">
<th>Schöneck</th>
<th>--></th>
<th>Mühlleithen</th>
<th>13400m</th>
<th>hard</th>
<td>
<select name="runner" required id="id_runner">
<option value="">---------</option>
...
</select>
</td>
</tr>
</table>
我希望 <tr>
表现得像一个表单。
我试图找到一种方法来告诉 hx-trigger 监听 <select>
的更改事件。
如何告诉 htmx 在 select
更改后立即提交数据?
背景:这是一场接力赛,每条腿都是桌子上的一行。
解决方法
您需要使用 change
事件。术语 changed
确实有不同的含义。
<script src="https://unpkg.com/htmx.org@1.1.0"></script>
<table>
<tr hx-post="//example.com" hx-trigger="change">
<td>
<select name="runner">
<option value="a">a</option>
<option value="b">b</option>
</select>
</td>
</tr>
</table>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。