hx-delete
hx-delete
属性将导致元素向指定的 URL 发出 DELETE
,并使用交换策略将 HTML 交换到 DOM 中:
¥The hx-delete
attribute will cause an element to issue a DELETE
to the specified URL and swap
the HTML into the DOM using a swap strategy:
<button hx-delete="/account" hx-target="body">
Delete Your Account
</button>
此示例将导致 button
向 /account
发出 DELETE
并将返回的 HTML 交换到 body
的 innerHTML
中。
¥This example will cause the button
to issue a DELETE
to /account
and swap the returned HTML into
the innerHTML
of the body
.
¥Notes
hx-delete
不是继承的
¥hx-delete
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
要在 DELETE
成功后删除元素,请返回带有空主体的 200
状态代码;如果服务器以 204
响应,则不会进行交换,记录在此处:请求和响应
¥To remove the element following a successful DELETE
, return a 200
status code with an empty body; if the server responds with a 204
, no swap takes place, documented here: Requests & Responses