hx-gethx-get 属性将导致元素向指定的 URL 发出 GET,并使用交换策略将 HTML 交换到 DOM 中:
¥The hx-get attribute will cause an element to issue a GET to the specified URL and swap
the HTML into the DOM using a swap strategy:
<button hx-get="/example">Get Some HTML</button>
此示例将导致 button 向 /example 发出 GET 并将返回的 HTML 交换到 button 的 innerHTML 中。
¥This example will cause the button to issue a GET to /example and swap the returned HTML into
the innerHTML of the button.
¥Notes
hx-get 不是继承的
¥hx-get is not inherited
默认情况下,hx-get 通常不包含任何参数。你可以使用 hx-params 属性来更改此设置
¥By default hx-get usually does not include any parameters. You can use the hx-params
attribute to change this
NB:如果带有 hx-get 属性的元素也具有值,则除非明确移除,否则该值将作为参数包含在内。
¥NB: If the element with the hx-get attribute also has a value, this will be included as a parameter unless explicitly removed
你可以使用 hx-target 属性控制交换的目标
¥You can control the target of the swap using the hx-target attribute
你可以使用 hx-swap 属性控制交换策略
¥You can control the swap strategy by using the hx-swap attribute
你可以使用 hx-trigger 属性控制触发请求的事件
¥You can control what event triggers the request with the hx-trigger attribute
你可以通过多种方式控制随请求提交的数据,记录在此处:参数
¥You can control the data submitted with the request in various ways, documented here: Parameters
空的 hx-get:"" 将向当前 url 发出获取请求并交换当前 HTML 页面
¥An empty hx-get:"" will make a get request to the current url and will swap the current HTML page