hx-disabled-elt

hx-disabled-elt 属性允许你指定在请求期间将添加 disabled 属性的元素。此属性的值可以是:

¥The hx-disabled-elt attribute allows you to specify elements that will have the disabled attribute added to them for the duration of the request. The value of this attribute can be:

以下是按钮在请求期间将自行禁用的示例:

¥Here is an example with a button that will disable itself during a request:

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

当请求正在进行时,这将导致按钮标记为 disabled 属性,这将阻止进一步的点击。

¥When a request is in flight, this will cause the button to be marked with the disabled attribute, which will prevent further clicks from occurring.

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

¥The hx-disabled-elt attribute also supports specifying multiple CSS selectors separated by commas to disable multiple elements during the request. Here is an example that disables buttons and text input fields of a particular form during the request:

<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>

注释

¥Notes