【问题标题】:How to get Current State of checkbox in thymeleaf th:onclick?如何在百里香th:onclick中获取复选框的当前状态?
【发布时间】: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


【解决方案1】:

我的错,我忘记了它的价值:

function userSettings(userId,userChk) { alert(userChk.checked)}

【讨论】:

    猜你喜欢
    • 2015-03-25
    • 2018-03-19
    • 2014-07-17
    • 2020-03-02
    • 2022-01-14
    • 2018-09-12
    • 2019-08-10
    • 2021-01-09
    相关资源
    最近更新 更多