zoukankan      html  css  js  c++  java
  • 如何获取复选框的内容

    展示页面代码如下

    <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值

    System.out.println(cb.length);
    deptsMapper.deleteBatch(cb);
    return "depts";
    }

  • 相关阅读:
    spring注解集合
    spring工作原理理解
    Linux下mysql命令 导入 导出sql文件
    List和Set排序的实现
    LeetCode--树
    LeetCode--链表
    LeetCode--字符串
    LeetCode--贪心算法
    LeetCode--数组
    数据库编程基本练习题
  • 原文地址:https://www.cnblogs.com/wangxue1314/p/11908421.html
Copyright © 2011-2022 走看看