天天看點

jquery 批量删除前台jsp 加js加背景 spring

jsp頁面元素

jquery 批量删除前台jsp 加js加背景 spring
jquery 批量删除前台jsp 加js加背景 spring
jquery 批量删除前台jsp 加js加背景 spring

js

$(document).ready(function(){

     $("#checkAll").click(function() {

            $('input[name="subBox"]').prop("checked",this.checked);

        });

        var $subBox = $("input[name='subBox']");

        $subBox.click(function(){

            $("#checkAll").prop("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false);

        });

        $("#batchDel").click(function() {

                        var checkedNum = $("input[name='subBox']:checked").length;

                        if (checkedNum == 0) {

                            alert("請選擇至少一項!");

                            return;

                        }

                        // 批量選擇

                            if (confirm("确定要删除所選項目?")) {

                                var checkedList = new Array();

                                $("input[name='subBox']:checked").each(function() {

                                    checkedList.push($(this).val());

                                });

                                $.ajax( {

                                    type : "POST",

                                    url : "user/deleteUserByIds.do",

                                    data : {

                                        'ids' : checkedList.toString()

                                    },

                                    success : function(result) {

                                        alert("删除成功");

                                        $("[name ='subBox']:checkbox").attr(

                                                "checked", false);

                                        window.location.reload();

                                    }

                                });

                            }

                        });    

});

背景

    @RequestMapping(value="deleteUserByIds.do")

    @ResponseBody

    public Map<String,Object> deleteUserByIds(HttpServletRequest request,ModelMap map){

        Map<String,Object> result = new HashMap<String,Object>();

        result.put("success", false);

        String ids =request.getParameter("ids");

        String[] id = ids.split("\\,");

        for(int i=0;i<id.length;i++)

        {

            String userId= id[i];

            User user = userService.queryUserById(Integer.parseInt(userId));

            user.setFlag(1);

            userService.updateUser(user);

        }

        result.put("success", true);

        return result;

    }

繼續閱讀