[Wise] school - bulk delete front and back major code

The front end of the list headers:

<tr>
					<th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose" id="allChoose" ></th>
</tr>

The front end of the list of table of contents:

<c:forEach items="${ulist }" var="data">
				<tr data-id="1">
					<td><input type="checkbox" name="checkboxBtn" value="${data.id }"></td>
				</tr>

Select the JS code:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
	<script type="text/javascript">
        $(function(){
            $('#allChoose').click(function(){
                $('input[type=checkbox]').attr('checked', $(this).attr('checked'));
            });
        });
	</script>

Remove all front-end functions:

        function delAll(){
            var s = document.getElementsByName("checkboxBtn");
            var s2 = "";
            for( var i = 0; i < s.length; i++ )
            {
                if ( s[i].checked ){
                    s2 += s[i].value+",";
                }
            }
            s2 = s2.substr(0,s2.length-1);
            alert(s2);
            location.href = "servletusers?do=delAll&id="+s2; //这里传过去的是已逗号分隔开的id,需要在后面的页面内取出
        }

Servlet layer:

if (dos.equals("delAll")) {

            String uids = request.getParameter("id");
            String[] uid = uids.split(",");
            for(int i=0;i<uid.length;i++){
                /*System.out.println("uid["+i+"]="+uid[i]);*/
                int id = Integer.parseInt(uid[i]);
                int i_del= ud.delUser(id);
                if(i_del!=1) {
                    out.print("<script>alert('删除失败!');"
                            + "window.location='servletusers?do=index';</script>");
                }
                if(i==uid.length-1) {
                    out.print("<script>alert('删除成功!');"
                            + "window.location='servletusers?do=index';</script>");
                }
            }
            return;
        }

Guess you like

Origin blog.csdn.net/weixin_39593940/article/details/91778852