hx-disabled-elt

hx-disabled-elt 属性允许您指定在请求持续时间内将添加 disabled 属性的元素。该属性的值可以是:

以下是一个示例,其中一个按钮将在请求期间禁用自身:

<button hx-post="/example" hx-disabled-elt="this">
    Post It!
</button>

当请求进行中时,这将导致按钮被标记为具有 disabled 属性,从而防止进一步的点击发生。

hx-disabled-elt 属性还支持使用逗号分隔的多个 CSS 选择器来指定在请求期间禁用多个元素。以下是一个示例,该示例在请求期间禁用特定表单的按钮和文本输入字段:

<form hx-post="/example" hx-disabled-elt="find input[type='text'], find button">
    <input type="text" placeholder="Type here...">
    <button type="submit">Send</button>
</form>

请注意,您还可以使用 inherit 关键字来继承父元素的禁用元素值,并添加额外的禁用元素 CSS 选择器:

<main hx-disabled-elt="#logout-button">
    ...
  <form hx-post="/example" hx-disabled-elt="inherit, find input[type='text'], find button">
    <input type="text" placeholder="Type here...">
    <button type="submit">Send</button>
  </form>
</main>

注意事项