对话框

可以使用 hx-prompthx-confirm 属性触发对话框。这些是由触发 AJAX 请求的用户交互触发的,但只有在对话框被接受时才会发送请求。

¥Dialogs can be triggered with the hx-prompt and hx-confirmattributes. These are triggered by the user interaction that would trigger the AJAX request, but the request is only sent if the dialog is accepted.

<div>
  <button class="btn primary"
          hx-post="/submit"
          hx-prompt="Enter a string"
          hx-confirm="Are you sure?"
          hx-target="#response">
    Prompt Submission
  </button>
  <div id="response"></div>
</div>

用户提供给提示对话框的值通过 HX-Prompt 标头发送到服务器。在这种情况下,服务器只是回显用户输入。

¥The value provided by the user to the prompt dialog is sent to the server in a HX-Prompt header. In this case, the server simply echos the user input back.

User entered <i>${response}</i>
Server Requests ↑ Show

🔗Demo