展示页面代码如下

<form action="depts.do?flag=delete" name="myform" method="post">
<input type="checkbox" value="1" name="cb" />1
<input type="checkbox" value="2" name="cb" />2
<input type="checkbox" value="3" name="cb" />3 <input type="button" value="提交1" onclick="getvalues()"/> <input type="submit" value="提交2" />
</form>

一、利用js+jQuery获取复选框内容

<script type="text/javascript">
function getvalues(){
//定义一个空数组
var arr=[];
$("input[name='cb']:checked").each(function(i){
//把所有被选中的复选框的值存入数组
arr[i]=$(this).val();
})
console.log(arr);
}
</script>

如何获取复选框的内容

 

 

二、在控制层获取复选框的内容

@RequestMapping(value = "depts.do",params = "flag=delete")
//String视图解析器
public String delete(String[] cb,ModelMap mp) {

//String[] cb cb:对应复选框的name值

}

相关文章:

  • 2022-12-23
  • 2021-09-07
  • 2021-09-21
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-06
  • 2021-12-06
  • 2022-12-23
  • 2021-08-26
  • 2023-01-28
相关资源
相似解决方案