hx-post
hx-post
属性将导致元素向指定的 URL 发出 POST
,并使用交换策略将 HTML 交换到 DOM 中:
¥The hx-post
attribute will cause an element to issue a POST
to the specified URL and swap
the HTML into the DOM using a swap strategy:
<button hx-post="/account/enable" hx-target="body">
Enable Your Account
</button>
此示例将导致 button
向 /account/enable
发出 POST
并将返回的 HTML 交换到 body
的 innerHTML
中。
¥This example will cause the button
to issue a POST
to /account/enable
and swap the returned HTML into
the innerHTML
of the body
.
¥Notes
hx-post
不是继承的
¥hx-post
is not inherited
你可以使用 hx-target 属性控制交换的目标
¥You can control the target of the swap using the hx-target attribute
你可以使用 hx-swap 属性控制交换策略
¥You can control the swap strategy by using the hx-swap attribute
你可以使用 hx-trigger 属性控制触发请求的事件
¥You can control what event triggers the request with the hx-trigger attribute
你可以通过多种方式控制随请求提交的数据,记录在此处:参数
¥You can control the data submitted with the request in various ways, documented here: Parameters