我是django开发人员,我是htmx的新手。我想知道是否有一种在htmx中实现onselect事件的简单方法。
我有以下下拉列表:

当角色被选中"onselect“时,我希望使用htmx(不是jquery或javascript)向后端发送http请求。
我该怎么做?
任何帮助都是非常感谢的!谢谢!
尝试在htmx文档上搜索"onselect“,但是没有内置的实现。尝试搜索"onselect htmx“堆栈溢出,但我找不到有用的帖子。
发布于 2022-11-30 08:46:14
发布于 2022-12-01 09:34:01
我在重读文档时找到了答案。
我在[hx-trigger]事件hx触发器上找到了解决方案
<select
class="custom-select"
id="role"
name="role"
hx-post="{% url 'set_user_role' user.id %}"
hx-trigger="change">
<option value=""></option>
{% for role in roles %}
<option value="{{role.id}}"
{% if role == current_role %}selected{% endif %}
>{{role.name}}</option>
{% endfor %}
</select>https://stackoverflow.com/questions/74621515
复制相似问题