5月1日 RIA 周二

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
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>My JSP 'list.jsp' starting page</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">
    -->

  <script type="text/javascript" src="js/jquery-1.8.2.js"></script>
  <script type="text/javascript">
    //全选 全不选 反选
    $(function (){
                $("[value='全选']").click(function (){
                    $(".ch").attr("checked",true);
                });
                $("[value='全不选']").click(function (){
                    $(".ch").attr("checked",false);
                });
                $("[value='反选']").click(function (){
                    $(".ch").each(function (){
                        if($(this).attr("checked")){
                            $(this).attr("checked",false);
                        }else{
                            $(this).attr("checked",true);
                        }
                    });
                });
        //新增--------------
        $("[value='增加']").click(function (){
            location="add.jsp";
        });
        //批量删除------------------
        $("[value='批量删除']").click(function(){
            var dels = "";
            $(".ch").each(function(){
                if($(this).attr("checked")){
                    dels += ","+$(this).val();
                }
            });
            var ids = dels.substring(1);
            alert(ids);
            if(confirm("确认删除吗?")){
                location="teacher?m=dels&ids="+ids;
            }else{
                alert("已取消");
            }
        });
    });
    function del(id){
        location="teacher?m=del&id="+id;
    }
    function upd(id){
        location="upd.jsp?id="+id;
    }
  </script>
  </head>

  <body>
    <table border="1px">
        <tr>
            <th></th>
            <th>id</th>
            <th>tname</th>
            <th>tage</th>
            <th>tsex</th>
            <th>thobby</th>
            <th>dept_id</th>
            <th>dept_name</th>
            <th><input type="button" value="增加"></th>
        </tr>
        <c:forEach var="li" items="${list}">
            <tr>
                <th><input type="checkbox" class="ch" value="${li.id}"></th>
                <th>${li.id}</th>
                <th>${li.tname}</th>
                <th>${li.tage}</th>
                <th>${li.tsex}</th>
                <th>${li.thobby}</th>
                <th>${li.dept_id}</th>
                <th>${li.dept_name}</th>
                <th><input type="button" value="修改" onclick="upd(${li.id})"><input type="button" value="删除" onclick="del(${li.id})"></th>
            </tr>
        </c:forEach>
    </table>
    <input type="button" value="全选">
    <input type="button" value="全不选">
    <input type="button" value="反选">
    <input type="button" value="批量删除">
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>My JSP 'add.jsp' starting page</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">
    -->

  <script type="text/javascript" src="js/jquery-1.8.2.js"></script>
  <script type="text/javascript" src="js/jquery.validate.js"></script>
  <script type="text/javascript">
    $(function (){
        //下拉框显示部门------------------------------
        $.ajax({
            url:"teacher?m=dept",
            type:"post",
            dataType:"json",
            success:function(msg){
                for(var i in msg){
                    $("#s1").append("<option value="+msg[i].id+">"+msg[i].dept_name+"</option>");
                }
            }
        });
        //ajax提交----------------------------------
        $("#for").validate({
            rules:{
                id:{required:true},
                tname:{required:true},
                tage:{required:true},
                tsex:{required:true},
                thobby:{required:true}
            },
            messages:{
                id:"不能为空",
                tname:"不能为空",
                tage:"不能为空",
                tsex:"不能为空",
                thobby:"不能为空"
            },
            submitHandler:function(){
                $.ajax({
                    url:"teacher?m=add",
                    type:"post",
                    data:$("#for").serialize(),
                    dataType:"text",
                    success:function(msg){
                        if(msg>0){
                            alert("增加成功");
                            location="teacher?m=list";
                        }else{
                            alert("增加失败");
                            location.reload();
                        }
                    }
                });
            }
        });
    });
  </script>
  </head>

  <body>
    <form id="for">
        id:<input type="text" name="id"><br>
        tname:<input type="text" name="tname"><br>
        tage:<input type="text" name="tage"><br>
        tsex:<input type="radio" name="tsex" value="男"><input type="radio" name="tsex" value="女"><br>
        thobby:<input type="checkbox" name="thobby" value="唱歌">唱歌
        <input type="checkbox" name="thobby" value="跳舞">跳舞
        <input type="checkbox" name="thobby" value="骑马">骑马
        <input type="checkbox" name="thobby" value="游泳">游泳<br>
        dept_name:
        <select name="dept_name" id="s1">

        </select>
        <br>
        <input type="submit" value="增加">
    </form>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>My JSP 'upd.jsp' starting page</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">
    -->

  <script type="text/javascript" src="js/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        var id = ${param.id};
        alert(id);
        //下拉框显示部门------------------------------
        $.ajax({
            url:"teacher?m=dept",
            type:"post",
            dataType:"json",
            success:function(msg){
                for(var i in msg){
                    $("#s1").append("<option value="+msg[i].id+">"+msg[i].dept_name+"</option>");
                }
            }
        });
        //ajax回显数据
        $.ajax({
            url:"teacher?m=upd",
            type:"post",
            data:{id:id},
            dataType:"json",
            success:function(msg){
                $("#id").val(msg.id);
                $("#tname").val(msg.tname);
                $("#tage").val(msg.tage);
                $("[value="+msg.tsex+"]").attr("checked",true);
                var hob = msg.thobby;
                var hobby = hob.split(",");
                for(var i in hobby){
                    $("[value="+hobby[i]+"]").attr("checked",true);
                }
                $("#s1").val(msg.dept_id);
            }

        });
            //ajax修改数据
        function update(){
            $.ajax({
                url:"teacher?m=update",
                type:"post",
                data:$("#for").serialize(),
                dataType:"text",
                success:function(msg){
                    if(msg>0){
                        alert("修改成功");
                        location="teacher?m=list";
                    }else{
                        alert("修改失败");
                        location.reload();
                    }

                }
            });
        }
    </script>
  </head>

  <body>
    <form id="for">
        <input type="hidden" name="id" id="id"><br>
        tname:<input type="text" name="tname" id="tname"><br>
        tage:<input type="text" name="tage" id="tage"><br>
        tsex:<input type="radio" name="tsex" value="男" id="tsex"><input type="radio" name="tsex" value="女" id="tsex"><br>
        thobby:<input type="checkbox" name="thobby" value="唱歌">唱歌
        <input type="checkbox" name="thobby" value="跳舞">跳舞
        <input type="checkbox" name="thobby" value="骑马">骑马
        <input type="checkbox" name="thobby" value="游泳">游泳<br>
        dept_name:
        <select name="dept_name" id="s1">

        </select>
        <br>
    </form>
        <input type="button" value="修改" onclick="update()">
  </body>
</html>

我们必须时刻保持残酷和狂热,直至死亡。
——希特勒

猜你喜欢

转载自blog.csdn.net/helloworld_1996/article/details/80160503