To pass parameters using thymeleaf's onclick event, you can use the th:attr attribute to set the value of the onclick attribute dynamically. Here's an example:\n\nhtml\n<button th:attr="onclick='myFunction('\' + ${param} + '\')'">Click me</button>\n\n\nIn this example, ${param} is the parameter you want to pass to the myFunction() JavaScript function. The th:attr attribute is used to set the value of the onclick attribute dynamically.\n\nNote that the single quotes (') are used to wrap the parameter value, and the backslash (\) is used to escape the single quotes within the JavaScript code.\n\nYou can replace myFunction with the actual JavaScript function name you want to call, and ${param} with the parameter value you want to pass.


原文地址: https://www.cveoy.top/t/topic/pwCv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录