ajax带checkbox选择值到后台

本文介绍了一个简单的JavaScript函数togglefun,用于实现表单中复选框的全选功能,并通过sysnycdata函数执行操作将选中的值传送到后台。此外,还展示了如何在后端接收这些数据。
function togglefun(checkbox){//全选
        $('input[name=cids]').prop('checked', $(checkbox).prop('checked'));
    }
//执行操作将值传到后台
    function sysnycdata(){
        if($("input[name=cids]:checked").length<1){
            alert("请至少选择一条数据");
            return false
        }
            $.ajax({
                    cache: true,
                    type: "POST",
                    url:"后台地址",
                    data:$("#cidssformsubmit").serialize(),
                    async: false,
                    error: function(request) {
                        alert("Connection error");
                    },
                    success: function(data) {
                        data=eval("("+data+")");
                        
                    }
             });
        
    }

 

 
   <form action="?" method="post" id="cidssformsubmit" >
              <table class="adv_query_list">
                  <tbody>
                      <tr class="search_title_show">
                          <td align="center"><input type="checkbox" name="idschk"  onclick="togglefun(this)"   /></td>
                      </tr>
                       <tr align="center" class="tdbg">
                          <td><input type="checkbox" name="cids"  value="${it[0]}" /></td>
                    </tr>
                  </tbody>
              </table>
          </form>

  

    @RequestMapping(value = "execute") 
    @ResponseBody
    public String execute(Long[] cids,HttpServletRequest request, Model model) throws Exception {
        int errorCount=0;
        try {
            if(null!=cids&&cids.length>0){
                for (int  i = 0; i < cids.length; i++) {
                    System.out.println(cids[i]);
                }
            }
        } catch (Exception e) {
        }
        return "{'errorCount':'"+errorCount+"'}";
    }

 

 

转载于:https://www.cnblogs.com/yy123/p/4329375.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值