hx-confirmhx-confirm 属性允许你在发出请求之前确认操作。当操作具有破坏性并且你想确保用户确实想要执行此操作时,此功能非常有用。
¥The hx-confirm attribute allows you to confirm an action before issuing a request. This can be useful
in cases where the action is destructive and you want to ensure that the user really wants to do it.
这是一个例子:
¥Here is an example:
<button hx-delete="/account" hx-confirm="Are you sure you wish to delete your account?">
Delete My Account
</button>
¥Event details
hx-confirm 触发的事件在其 detail 中包含其他属性:
¥The event triggered by hx-confirm contains additional properties in its detail:
触发事件:触发原始请求的事件
¥triggeringEvent: the event that triggered the original request
issueRequest(skipConfirmation=false):可用于确认 AJAX 请求的回调
¥issueRequest(skipConfirmation=false): a callback which can be used to confirm the AJAX request
问题:HTML 元素上 hx-confirm 属性的值
¥question: the value of the hx-confirm attribute on the HTML element
¥Notes
hx-confirm 是继承的,可以放在父元素上
¥hx-confirm is inherited and can be placed on a parent element
hx-confirm 默认使用浏览器的 window.confirm。你可以自定义此行为,如 在此示例中 所示。
¥hx-confirm uses the browser’s window.confirm by default. You can customize this behavior as shown in this example.
可以将布尔值 skipConfirmation 传递给 issueRequest 回调;如果为 true(默认为 false),则不会调用 window.confirm 并直接发出 AJAX 请求
¥a boolean skipConfirmation can be passed to the issueRequest callback; if true (defaults to false), the window.confirm will not be called and the AJAX request is issued directly