hx-select
hx-select
属性允许你从响应中选择要交换的内容。此属性的值是从响应中选择的元素的 CSS 查询选择器。
¥The hx-select
attribute allows you to select the content you want swapped from a response. The value of
this attribute is a CSS query selector of the element or elements to select from the response.
以下是选择响应内容子集的示例:
¥Here is an example that selects a subset of the response content:
<div>
<button hx-get="/info" hx-select="#info-detail" hx-swap="outerHTML">
Get Info!
</button>
</div>
因此,此按钮将发出 GET
到 /info
,然后选择 id 为 info-detail
的元素,这将替换 DOM 中的整个按钮。
¥So this button will issue a GET
to /info
and then select the element with the id info-detail
,
which will replace the entire button in the DOM.
¥Notes
hx-select
是继承的,可以放在父元素上
¥hx-select
is inherited and can be placed on a parent element