在button.onclick属性上显示i18n消息

Kai*_*ugo 1 thymeleaf

我应如何在以下代码中显示Thymeleaf i18n消息:

<button th:text="#{msg_warning}" onclick="return confirm("[[#{msg_confirm_warning}]]")">
    Delete
</button>
Run Code Online (Sandbox Code Playgroud)

即使使用 th:attr

<button th:text="#{msg_warning}" th:attr="onclick='return confirm(\'#{msg_confirm_warning}\');'">
    Delete
</button>
Run Code Online (Sandbox Code Playgroud)

输出应该msg_confirm_warning是单击按钮时的字符串值.但它显示[[#{msg_confirm_warning}]]字符串.

Kai*_*ugo 6

好吧,我想我做错了语法.使用下面的代码,它解决了我的问题.

<button th:text="#{msg_warning}" th:attr="onclick='return confirm(\'' + #{msg_confirm_warning} + '\');'">
    Delete
</button>
Run Code Online (Sandbox Code Playgroud)