首页 > 解决方案 > 我如何在多个复选框上调用控制器类中的方法来更新spring mvc中的记录

问题描述

一旦我选择了一个我想更新数据库的复选框,我就有一个带有复选框的数据表,当我选择所有复选框时,所有记录都应该使用常见值(如 1)进行更新;

提前致谢。

标签: spring-mvc

解决方案


您可以使用任何客户端语言进行操作。但是,在这里我使用了 jquery。

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">        </script>
<script>

$(document).ready(function(){
   $("button").click(function(){
    $("input[type=checkbox]").each( function(i, field){
    if($("#c"+(i+1)).prop("checked")){
        $("#results").append("you have selected :"+field.name );
    }

    });
  });
});
</script>
</head>
<body>


  one: <input type="checkbox" name="1" id="c1" value="1" ><br>
  two: <input type="checkbox" name="2" id="c2" value="2"><br>
   three: <input type="checkbox" name="3" id="c3" value="3"><br>
  four: <input type="checkbox" name="4" id="c4" value="4"><br>


<button>click here</button>

<div id="results"></div>

</body>
</html>

在客户端对象创建时使用上述方式。


推荐阅读