【发布时间】:2021-10-28 03:58:17
【问题描述】:
我有一个复选框,我用 th:onclick 调用了一个函数。此函数在我单击它后采用复选框的值。但我不知道如何在 th:onclick 中获取复选框的状态。代码如下所示:
<input type="checkbox" th:onclick="'javascript:userSettings(' + ${user.id} + ', this );'" th:checked="${user.enabled}" />
我的功能:
function userSettings(userId,userChk) { alert(userChk)}
点击复选框后,“userChk”的值为undefiend。
我该如何解决这个问题?
【问题讨论】:
-
例如勾选复选框后,checked的值为false。我需要将这个“假”传递给我的函数。
-
你在用jquery吗?
-
是的,我正在使用 jquery。但现在我只想获取“userChk”的值。
标签: javascript spring thymeleaf