网页的全选和反选

1 页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>管理员首页</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
<!-- 引用Bootstrap -->
<link href="<%=basePath%>/boostrap/css/bootstrap.min.css"
    rel="stylesheet">

</head>

<body>
    <div class="container">
        <div class="row clearfix">
            <div class="col-md-12 column">
            </div>
        </div>
        <div class="row clearfix">
            <div class="col-md-12 column">
                <c:choose>
                    <c:when test="${listNotexamined_info != null }">
                        <h3>
                            <c:out value="${listNotexamined_info }"></c:out>
                        </h3>
                    </c:when>
                    <c:otherwise>
                        <c:if test="${newsList != null && newsList.size() != 0 }">
                            <form action="root/publishAllNews" method="post">
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <!-- 全选按钮 -->
                                             <th><input name="checkAll" id="checkAll" type="checkbox" />
                                                全选</th>
                                            <th>标题</th>
                                            <th>时间</th>
                                            <th>城市</th>
                                            <th>类别</th>
                                            <th>编辑</th>
                                            <th>是否审核</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <c:forEach items="${newsList }" var="news">
                                            <tr>
                                                <!-- 逐个选择按钮 -->
                                                <td><input name="newsId" type="checkbox"
                                                    value=<c:out value="${news.id }"/> /></td>
                                                    
                                                    
                                                    <!--  
                                                    
                                                    省略。。。。。。
                                                    
                                                     -->
                                                    
                                                    
                                                    
                                                 <td><button id="<c:out value="${news.id }"/>"
                                                        class="btn btn-default" onclick="publicNews(this)">发布</button></td>
                                            </tr>
                                        </c:forEach>
                                    </tbody>
                                </table>
                                <hr/>
                                <p align="right">
                                    <input type="submit" value="发布选中" class="btn btn-default" />
                                </p>
                            </form>
                        </c:if>
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
    </div>
</body>


2 Js

$(function(){
    
    //全选和全反选
    $("#checkAll").click(function(){
        
        var isChecked = $(this).prop("checked");
        
         $("input[name='newsId']").prop("checked", isChecked);
    });
});



3 后台

public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        String[] newsIds = request.getParameterValues("newsId");
        
        
    }


4界面

145415_Za7G_2328736.png

转载于:https://my.oschina.net/ChiLin/blog/638518

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值