首页 > 其他分享 >2023年11月2日

2023年11月2日

时间:2023-12-21 09:11:06浏览次数:25  
标签:11 const border value getElementById 2023 document data

今天我们实现学生的前端信息,学生部分的前端代码,学生部分的后端代码在User的后端代码中

register.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生注册</title>
    <style>
        button {
            display: block;
            margin-top: 10px;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

        .centered-form {
            text-align: center;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        .bordered-form {
            border: 2px solid #000; /* 边框样式 */
            padding: 20px; /* 可选的内边距 */
            background-color: #f0f0f0; /* 可选的背景颜色 */
        }
    </style>
</head>
<body>
<div class="centered-form">
    <div class="bordered-form">
        <h1>学生注册</h1>
        <form id="register">
            <label for="College">所属学院:</label><input type="text" id="College">
            <br>
            <label for="Professionals">所属专业:</label><input type="text" id="Professionals">
            <br>
            <label for="Class">所属班级:</label><input type="text" id="Class">
            <br>
            <label for="id">学号:</label><input type="text" id="id">
            <br>
            <label for="StuName">姓名:</label><input type="text" id="StuName">
            <br>
            <label>性别:</label>
            <div id="sex">
                <label><input type="radio" name="sex" value="男"> 男</label>
                <label><input type="radio" name="sex" value="女"> 女</label>
            </div>
            <label for="Phone">手机号:</label><input type="text" id="Phone">
            <br>
            <label for="Position">职位:</label>
            <select id="Position" name="Position" required>
                <option value="">请选择</option>
                <option value="班长">班长</option>
                <option value="副班长">副班长</option>
                <option value="团支书">团支书</option>
                <option value="学习委员">学习委员</option>
                <option value="宿舍长">宿舍长</option>
                <option value="无">无</option>
            </select>
            <div class="centered-buttons">
                <button type="submit" style="display: block; margin: 0 auto;">注册</button>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    document.getElementById('register').addEventListener('submit', function (event) {
        event.preventDefault();
        const id = document.getElementById('id');
        const StuName = document.getElementById('StuName');
        const grade = document.getElementById('Class');
        const sex = document.querySelectorAll('input[name="sex"]');
        let s;
        sex.forEach(radio => {
            if (radio.checked) {
                s = radio.value;
                alert(s);
            }
        });
        const College = document.getElementById('College');
        const Professionals = document.getElementById('Professionals');
        const Phone = document.getElementById('Phone');
        const Position = document.getElementById('Position');
        console.log(id.value + StuName.value + s + grade.value + College.value + Professionals.value + Phone.value + Position.value);
        const requestUrl = 'http://localhost:8080/user/add';
        fetch(requestUrl, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(
                {
                    stuId: id.value,
                    stuName: StuName.value,
                    grade: grade.value,
                    sex: s,
                    college: College.value,
                    professionals: Professionals.value,
                    phone: Phone.value,
                    position: Position.value,
                    state: 0
                })
        })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success') {
                    alert("添加成功,请等待审核");
                    console.log(data.data.grade);
                } else {
                    alert("添加失败  " + data.msg);
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    })
</script>
</html>
复制代码

student.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生信息管理系统</title>
    <style>
        .form {
            width: 600px;
            margin: 0 auto;
            /*border: 1px solid red;*/
        }

        .form table {
            margin: 0 auto;
        }

        .form table tr td {
            width: 100px;
            height: 30px;
            border: 1px solid #000;
            text-align: center;
        }

        button {
            display: block;
            margin-top: 10px;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<h1 style="text-align: center">学生信息管理系统</h1>
<script>
    // 获取URL中的用户名参数
    var urlParams = new URLSearchParams(window.location.search);
    var username = urlParams.get('username');
    console.log(username);
</script>
<div class="form">
    <table border="1px" cellspacing="0" width="600px">
        <tr>
            <th>编号</th>
            <th>功能</th>
        </tr>
        <tr>
            <td>1</td>
            <td>
                <button id="select1">查询学生个人信息</button>
            </td>
        </tr>
        <tr>
            <td>2</td>
            <td>
                <button id="update">修改密码</button>
            </td>
        </tr>
        <tr>
            <td>3</td>
            <td>
                <button id="select2">查询考试信息</button>
            </td>
        </tr>
    </table>
</div>
</body>
<script>
    document.getElementById("select1").addEventListener("click", function () {
        window.location.href = "student1.html?username=" + encodeURIComponent(username);
    });
    document.getElementById('update').addEventListener('click', function () {
        window.location.href = "student2.html?username=" + encodeURIComponent(username);
    })
    document.getElementById("select2").addEventListener("click", function () {
        window.location.href = "student3.html?username=" + encodeURIComponent(username);
    })
</script>
</html>
复制代码

student1.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生信息</title>
    <style>
        .form {
            width: 600px;
            margin: 0 auto;
            /*border: 1px solid red;*/
        }

        .form table {
            margin: 0 auto;
        }

        .form table tr td {
            width: 100px;
            height: 30px;
            border: 1px solid #000;
            text-align: center;
        }

        button {
            display: block;
            margin-top: 10px;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<h1 style="text-align: center">个人信息</h1>
<div class="form">
    <div id="container">
    </div>
</div>
</body>
<script>
    // 获取URL中的用户名参数
    var urlParams = new URLSearchParams(window.location.search);
    var username = urlParams.get('username');
    console.log("用户名为:" + username);
    const requestUrl = `http://localhost:8080/user/person/${username}`;

    function display() {
        fetch(requestUrl, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
        })
            .then(response => response.json())
            .then(data => {
                if (data.msg === 'success') {
                    generateTable(data.data);
                } else {
                    alert("此结果不存在");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }

    display();
</script>
<script>
    function generateTable(data) {
        const tableContainer = document.getElementById("container");

        // 清空 tableContainer 中的所有子节点
        while (tableContainer.hasChildNodes()) {
            tableContainer.removeChild(tableContainer.firstChild);
        }
        const table = document.createElement("table");
        const tableBody = document.createElement("tbody");

        let row = document.createElement("tr");
        row.innerHTML = '<td>学号/用户名</td><td>姓名</td><td>年级</td><td>性别</td><td>学院</td><td>专业</td><td>手机号</td><td>职位</td><td>审核状态</td>';
        tableBody.appendChild(row);
        let s = "审核中";
        if (data.state === 1) {
            s = "审核通过";
        } else if (data.state === -1) {
            s = "审核未通过";
        }
        row = document.createElement("tr");
        row.innerHTML = `<td>${data.stuId}</td><td>${data.stuName}</td><td>${data.grade}</td><td>${data.sex}</td><td>${data.college}</td><td>${data.professionals}</td><td>${data.phone}</td><td>${data.position}</td><td>${s}</td>`;
        tableBody.appendChild(row);

        table.appendChild(tableBody);
        tableContainer.appendChild(table);
    }
</script>
</html>
复制代码

student2.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <style>
        button {
            display: block;
            margin-top: 10px;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

        .centered-form {
            text-align: center;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        .bordered-form {
            border: 2px solid #000; /* 边框样式 */
            padding: 20px; /* 可选的内边距 */
            background-color: #f0f0f0; /* 可选的背景颜色 */
        }
    </style>
</head>
<body>
<h1 style="text-align: center">修改密码</h1>
<div class="centered-form">
    <div class="bordered-form">

        <label for="old">旧密码</label>
        <input type="text" id="old" required>
        <br>
        <label for="new1">新密码</label>
        <input type="text" id="new1" required>
        <br>
        <label for="new2">确认新密码</label>
        <input type="text" id="new2" required>
        <div id="match"></div>
        <br>
        <button id="update" style="display: block; margin: 0 auto;">更改密码</button>
    </div>
</div>
</body>
<script>
    const newPassword1 = document.getElementById("new1");
    const newPassword2 = document.getElementById("new2");
    const passwordMatchMessage = document.getElementById("match");

    function checkPasswordMatch() {
        const password1 = newPassword1.value;
        const password2 = newPassword2.value;

        if (password1 === password2) {
            passwordMatchMessage.textContent = "两次密码一致";
            passwordMatchMessage.style.color = "green";
        } else {
            passwordMatchMessage.textContent = "两次密码不一致";
            passwordMatchMessage.style.color = "red";
        }
    }

    newPassword1.addEventListener("input", checkPasswordMatch);
    newPassword2.addEventListener("input", checkPasswordMatch);
</script>
<script>
    var urlParams = new URLSearchParams(window.location.search);
    var username = urlParams.get('username');
    console.log("用户名为:" + username);
    document.getElementById('update').addEventListener('click', function () {
        const requestUrl = `http://localhost:8080/user/getUser/${username}`;
        fetch(requestUrl, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
        })
            .then(response => response.json())
            .then(data => {
                if (data.msg === 'success') {
                    console.log(data);
                    deal(data.data);
                } else {
                    alert("此结果不存在");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    })
</script>
<script>
    function deal(data) {
        const old = document.getElementById('old').value;
        const new1 = document.getElementById('new1').value;
        const new2 = document.getElementById('new2').value;
        const password=data.password;
        console.log("密码为   "+password);
        if(old!==password)
        {
            alert("您输入的旧密码有误");
        }
        else if(old!==password&&new1!==new2)
        {
            alert("输入的两次密码不一致");
        }
        else if (old === password && new1 === new2) {
            const requestUrl = `http://localhost:8080/user/update/${username}/${new1}`;
            fetch(requestUrl, {
                method: 'PUT',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
                .then(response => response.json())
                .then(data => {
                    if (data.msg === 'success') {
                        console.log(data+"   111");
                        alert("修改成功,请您重新登陆");
                        window.location.href="http://localhost:8080/index.html";
                    } else {
                        alert("修改失败");
                    }
                })
                .catch(error => {
                    alert("请求失败,请重试");
                    console.error(error);
                });
        }
    }
</script>
</html>
复制代码

student3.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>考试信息查询</title>
    <style>
        .reSet {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            cursor: pointer;
        }

        .form {
            width: 600px;
            margin: 0 auto;
            /*border: 1px solid red;*/
        }

        .form table {
            margin: 0 auto;
        }

        .form table tr td {
            width: 100px;
            height: 30px;
            border: 1px solid #000;
            text-align: center;
        }

        button {
            display: block;
            margin-top: 10px;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

        .centered-form {
            text-align: center;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        .bordered-form {
            border: 2px solid #000; /* 边框样式 */
            padding: 150px; /* 可选的内边距 */
            background-color: #f0f0f0; /* 可选的背景颜色 */
        }
    </style>
</head>
<body>
<h1 style="text-align: center">考试信息查询</h1>
<!--边框居中-->
<div class="centered-form">
    <!--    增加边框-->
    <div class="bordered-form">
        <!--        调整边框大小-->
        <div class="form">
            <form id="selectForm">
                <label for="courseName">课程名称:</label>
                <input type="text" id="courseName" name="courseName" required>
                <br>
                <label for="courseClass">授课班级</label>
                <input type="text" id="courseClass" name="courseClass" required>
                <br>
                <label for="courseMajor">授课专业</label>
                <input type="text" id="courseMajor" name="courseMajor" required>
                <br>
                <button type="submit" style="display: block; margin: 0 auto;">查询</button>
            </form>
            <div id="container">

            </div>
        </div>
    </div>
</div>
</body>
<script>
    document.getElementById('selectForm').addEventListener('submit', function (event) {
        event.preventDefault();
        const courseName = document.getElementById('courseName').value;
        const courseClass = document.getElementById('courseClass').value;
        const courseMajor = document.getElementById('courseMajor').value;
        const requestUrl = `http://localhost:8080/user/selectTest/${courseName}/${courseClass}/${courseMajor}`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(response => response.json())
            .then(data => {
                if (data.msg === 'success') {
                    alert("查询成功");
                    generate(data.data, courseName, courseClass, courseMajor);
                } else {
                    alert("查询失败");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    });
</script>
<script>
    function generate(data, courseName, courseClass, courseMajor) {
        const tableContainer = document.getElementById("container");
        // 清空 tableContainer 中的所有子节点
        while (tableContainer.hasChildNodes()) {
            tableContainer.removeChild(tableContainer.firstChild);
        }
        const table = document.createElement("table");
        const tableBody = document.createElement("tbody");
        let row = document.createElement("tr");
        row.innerHTML = '<td>申请日期</td><td>课程名称</td><td>授课班级</td><td>授课专业</td><td>审核状态</td>';

        tableBody.appendChild(row);
        // 查询方式是按姓名查询或多条查询
        for (let i = 0; i < data.length; i++) {
            let s;
            if (data[i].auditStatus === 0) {
                s = "待审核";
            } else if (data[i].auditStatus === -1) {
                s = "未通过";
            } else if (data[i].auditStatus === 1) {
                s = "已符合";
            } else if (data[i].auditStatus === 2) {
                s = "已通过";
            }
            row = document.createElement("tr");
            let p1 = data[i].professional;
            let p2 = data[i].professionalConclusion;
            if (data[i].professional === null) {
                p1 = "未进行";
                p2 = "未进行";
            }
            let r1 = data[i].Reasonable;
            let r2 = data[i].ReasonableConclusion;
            if (data[i].Reasonable === undefined) {
                r1 = "未进行";
                r2 = "未进行";
            }
            let d = data[i].cardDate;
            row.innerHTML = `<td><button type="button" id="search" onclick="redirectToSelectAll('${courseName},${courseClass},${courseMajor}')">${d}</button></td><td>${data[i].courseName}</td><td>${data[i].courseClass}</td><td>${data[i].courseMajor}</td><td>${s}</td>`;
            tableBody.appendChild(row);
            table.appendChild(tableBody);
            tableContainer.appendChild(table);
        }
    }

    function redirectToSelectAll(parameters) {
        var [courseName, courseClass, courseMajor] = parameters.split(',');

        // 对每个参数进行处理,比如 URL 编码
        var encodedCourseName = encodeURIComponent(courseName.trim());
        var encodedCourseClass = encodeURIComponent(courseClass.trim());
        var encodedCourseMajor = encodeURIComponent(courseMajor.trim());

        // 构建 URL
        var targetURL = `../All/test.html?courseName=${encodedCourseName}&courseClass=${encodedCourseClass}&courseMajor=${encodedCourseMajor}`;

        // 重定向
        window.location.href = targetURL;
    }
</script>
</html>
复制代码

标签:11,const,border,value,getElementById,2023,document,data
From: https://www.cnblogs.com/Christmas77/p/17918225.html

相关文章

  • 大二打卡(11.16)
    今天做了什么:今天的高铁票,老姐要结婚了,迫不及待穿上周一买的那身巨帅的大衣,但是大衣已经被表姐拿回去了,前几天看到老姨他们拍的视频,家门口已经大变样了,喜庆,红艳,但是距离我亲眼目睹这一切还剩四次课,uml,体育课,数据结构跟离散数学,uml今天开始上实验,每周都是,这周的只是让你下载个建模......
  • 2023年10月20日
    二叉树的链式结构二叉树的数据结构:typedefstructNode{chardata;structNode*lchild,*rchild;}*Bitree,BiNode;分别为根,左孩子,右孩子二叉树的创建,先序遍历的方式如输入 “AB#CD###E#F##”voidcreatBitree(Bitree&T){charch;cin>>ch;if(ch=='#')T=NULL;else{T=newBi......
  • 11/13
    又是周一,上午是工程实训,下午是建民老师的课.还是servlet会执行doGet()方法其生命周期由容器来管理,分为4个阶段:1、加载和实例化:默认情况下,当Servlet第一次被访问时,由容器创建Servlet对象;非默认情况下,可以通过@WebServlet(urlPatterns="/demo",loadOnStartup=1)进行Servlet......
  • 2023年10月21日
    《代码大全2》是一个经典的软件开发书籍,是一本非常有价值的资源,包含了许多软件开发中的重要主题。书中提醒读者以解决问题为导向,不仅仅是完成任务。防御式编程,防御式编程不是指不让别人批评代码,而是指确保要承担的责任,保证方法不会因为传入错误数据而破坏,看似微小的防范,收益可能......
  • 2023-2024-120231329《计算机基础与程序设计》第13周学习总结
    作业信息这个作业属于哪个课程https://edu.cnblogs.com/campus/besti/2023-2024-1-CFAP这个作业要求在哪里https://www.cnblogs.com/rocedu/p/9577842.html这个作业的目标《C语言程序设计》第12章并完成云班课测试作业正文https://www.cnblogs.com/xjn123/p/17......
  • 2023-2024 20231313《计算机基础与程序设计》第十三周学习总结
    2023-202420231313《计算机基础与程序设计》第十二周学习总结作业速达作业课程班级链接作业要求计算机基础与程序设计第十三周学习总结作业内容《C语言程序设计》第12章并完成云班课测试作业正文我的作业目录教材总结总结学习过程的问题《C语言程序......
  • 2023.12.20 日记
    挺久没写的了。防止这里长草来写一点。上周并没有回家。周一去参加入团仪式,晚上回到纪中,汤老师找我谈话,本来以为是很严肃的一次警告,没想到,她和我谈了很多人生的意义。包括她的过去,我的现在。最近这一年我一直处于一种迷茫里。现在好了很多。这确实是一个负责的老师。老师分为......
  • 2023.12.20
    复习软件设计,明天就要考试了,加油!结构型模式(7种)适配器模式例子仿生机器人、加密适配器桥接模式例子模拟毛笔组合模式例子文件和文件夹水果盘装饰模式例子变形金刚、多重加密系统外观模式(门面模式) 例子电源总开关享元模式定义运用共享技术有效地支......
  • CSP&NOIP 2023 游记
    今日是2023.12.20.先写CSP吧。在本校考试。具体的记忆都模糊了。花了30分钟过了A,认为实在是不可置信。然后看B,感觉是括号匹配,首先有一个平方的算法,可以拿50分。看了一眼C,感觉是一坨屎。D当时觉得很难。于是15:00到16:00什么都没做。到了16:00想到B的解法......
  • 【2023年网络安全优秀创新成果大赛专刊】银行数据安全解决方案(天空卫士)
    在2023年网络安全优秀创新成果大赛,成都分站中,天空卫士银行数据安全方案获得优秀解决方案奖。与此同时,天空卫士受信息安全杂志邀请,编写《银行数据安全解决方案》。12月6日,天空卫士编写的《银行数据安全解决方案》做为优秀论文在信息安全杂志2023年11月增刊上发表。信息安全研究......