thymeleaf th:onclick
时间: 2023-09-24 18:07:20 浏览: 250
Thymeleaf is a Java-based templating engine commonly used for server-side rendering in web applications. The `th:onclick` attribute is a Thymeleaf-specific attribute used to bind JavaScript code to the `onclick` event of an HTML element.
By using `th:onclick`, you can execute custom JavaScript code when the element is clicked. Here's an example of how to use it:
```html
<button th:onclick="'myFunction()'" >Click me</button>
```
In this example, the `th:onclick` attribute is used to bind the `myFunction()` JavaScript function to the button's `onclick` event. When the button is clicked, the `myFunction()` function will be executed.
You can also pass dynamic values from Thymeleaf expressions to the JavaScript function. For example:
```html
<button th:onclick="'myFunction(' + ${id} + ')'" >Click me</button>
阅读全文