【问题标题】:How do i get changed value of a single checkbox in requestparam and pass it to ModelAndView in spring boot?我如何在 requestparam 中获取单个复选框的更改值并将其传递给 Spring Boot 中的 ModelAndView?
【发布时间】:2022-11-17 21:45:24
【问题描述】:

html文件:

     <html>
   <body>
      <label>
    <input type="checkbox" name="postcheckbox" />
        demo checkbox
    </label>
</body>
</html>

我想在我的控制器中获取更改复选框状态的值。

【问题讨论】:

    标签: java spring-boot spring-mvc http-request-parameters


    【解决方案1】:

    通过使用 Js

    var checkbox = document.querySelector("input[name=postcheckbox]");
    
    checkbox.addEventListener('change', function() {
      if (this.checked) {
        console.log("Checkbox is checked..");
        //pass to model
    
      } else {
        console.log("Checkbox is not checked..");
        //pass to model
    
      }
    });
    
    

    【讨论】:

      猜你喜欢
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      相关资源
      最近更新 更多