【问题标题】:disable button based on checkbox state in thymeleaf and springboot基于百里香叶和弹簧启动中的复选框状态禁用按钮
【发布时间】:2022-01-14 11:25:14
【问题描述】:

基于复选框状态,如果选中此复选框,我想启用按钮,反之亦然,使用带有 springboot 的 thymeleaf。 这是我尝试过的:

        <div>
            <label>
            <input type="checkbox" th:value="${test}">
                actif
                </label>
        </div>
        <div>
            <button [disabled]="${test == false}"  type="submit">Envoyer</button>
        </div>
        

在我的控制器中:

        private boolean test = false;
        model.addAttribute("test", test);

【问题讨论】:

  • 如果您希望此启用/禁用在不刷新页面的情况下动态发生,那么您需要使用 JavaScript。一旦你的 HTML 从 Thymeleaf 发送到浏览器,Thymeleaf 就不能再工作了。
  • 谢谢,我可以在提交表单后修改此逻辑并显示错误消息以避免您所说的

标签: html spring-boot thymeleaf


【解决方案1】:

正如 Wim Deblauwe 所提到的,正确做到这一点的唯一方法是使用 JavaScript。对于这种情况,它相对简单。见this answer for details

【讨论】:

    猜你喜欢
    • 2021-12-11
    • 2016-06-01
    • 2018-11-20
    • 2018-04-03
    • 2018-04-02
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    相关资源
    最近更新 更多