1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>简易学生信息管理系统</title> <style> * { margin: 0px; padding: 0px; font-size: 18px; }
h3 { text-align: center; margin: 20px 0px; font-size: 36px; }
.inputInfo { width: 800px; margin: 0px auto; margin-bottom: 18px; }
.inputInfo input[type="text"], .inputInfo input[type="number"] { width: 700px; height: 32px; border-radius: 4px; padding-left: 6px; }
.inputInfo input[type="radio"] { margin-right: 6px; margin-left: 6px; }
.inputInfo select { width: 100px; height: 32px; border-radius: 4px; }
.btnStyle { display: block; padding: 6px 12px; text-align: center; white-space: nowrap; vertical-align: middle; cursor: pointer; color: white; border: 1px solid transparent; border-radius: 8px; margin: 0px auto; margin-bottom: 20px; }
.createBtn { background-color: #d9534f; border-color: #d43f3a; }
.optionBtn { width: 800px; margin: 0px auto; }
.optionBtn>button { display: inline-block; margin-left: 10px; }
.averageBtn, .sortBtn { background-color: #E5E5E5; border-color: #E5E5E5; color: #333; margin: 20px auto; }
.studentList { width: 800px; margin: 0px auto; border-collapse: collapse; }
.studentList thead tr td { background-color: #6495ED; }
.studentList thead tr td>a { font-size: 24px; text-decoration: none; color: #333; }
.studentList td { height: 60px; text-align: center; border: 1px solid #ddd; font-size: 24px; }
.deleteBtn { background-color: #428bca; border-color: #357ebd; margin: 0px auto; }
.searchBtn { background-color: #5bc0de; border-color: #46b8da; height: 20px; margin: 0px 10px; font-size: 14px; }
.searchInfo { width: 800px; height: 50px; margin: 0px auto; line-height: 50px; font-size: 24px; }
.searchInfo>input { height: 28px; border-radius: 4px; padding-left: 6px; }
.searchInfo>button { height: 34px; font-size: 20px; line-height: 20px; display: inline-block; } </style> <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.47/vue.global.prod.js"></script> </head> <body> <div id="app"> <h3>学生信息录入系统</h3> <!-- 学生信息输入表单 --> <div class="inputInfo"> <label for="studentName">姓名:</label> <input type="text" id="studentName" v-model="StudentNewMessage.stuName" placeholder="请输入学生的姓名......" /> </div> <div class="inputInfo"> <label for="studentID">学号:</label> <input type="text" id="studentID" v-model="StudentNewMessage.stuID" placeholder="请输入学生的学号......"/> </div> <div class="inputInfo"> <label for="studentAge">年龄:</label> <input type="number" id="studentAge" v-model.number="StudentNewMessage.age" placeholder="请输入学生的年龄......"/> </div> <div class="inputInfo"> <span>性别:</span> <input type="radio" value="男生" name="gender" id="boy" v-model="StudentNewMessage.gender" /> <label for="boy">男生</label> <input type="radio" value="女生" name="gender" id="girl" v-model="StudentNewMessage.gender"/> <label for="girl">女生</label> </div> <div class="inputInfo"> <span>地址:</span> <select v-model="StudentNewMessage.address"> <option value="请选择">请选择</option> <option value="四川省">四川省</option> <option value="山东省">山东省</option> <option value="海南省">海南省</option> <option value="湖南省">湖南省</option> </select> </div> <button class="btnStyle createBtn" @click="insertStuMessage()">创建学生信息</button>
<hr /> <!-- 学生信息列表 --> <h3>学生信息列表</h3> <div class="optionBtn"> </div> <table class="studentList"> <thead> <tr> <td>姓名</td> <td>学号</td> <!-- // javascript:void(0) 用于阻止a标签的默认行为 阻止跳转--> <td><a href="javascript:void(0)" @click="StuAgeEstimate()">年龄↑</a></td> <td>性别</td> <td>地址</td> <td>操作</td> </tr> </thead> <tbody> <tr v-for="(item,index) in students" :key="item.stuID"> <td>{{item.stuName}}</td> <td>{{item.stuID}}</td> <td>{{item.age}}</td> <td>{{item.gender}}</td> <td>{{item.address}}</td> <td> <button class="btnStyle deleteBtn" @click="deleteStuMessage(index)">删除</button> </td> </tr> </tbody> </table> <div class="searchInfo"> 按姓名搜索:<input type="text" v-model="StuNameSearch" /> <button class="btnStyle searchBtn" @click="StuSearch()">搜索</button> </div> </div> <!-- 以下是Vue.js框架练习代码,请补充 --> <script> var app=Vue.createApp({ data(){ return { students: [{ stuName: '张三', stuID: 10, age: 20, gender: '男生', address: '四川省' }, { stuName: '李四', stuID: 11, age: 18, gender: '男生', address: '海南省' }, { stuName: '王五', stuID: 12, age: 19, gender: '女生', address: '山东省' } ], StudentNewMessage:{ stuName: '', stuID: '', age:0, gender: '', address: '' },//存储新添加的学生信息 } }, methods: { // 添加学生信息 insertStuMessage() { // 判断学生信息是否填写完整 // !== 用于判断两个值是否不相等 === 用于判断两个值是否相等 if (this.StudentNewMessage.stuName === '') { alert('学生姓名不能为空!'); return; } else if (this.StudentNewMessage.stuID === '') { alert('学生学号不能为空!'); return; } else if (this.StudentNewMessage.age === '' || this.StudentNewMessage.age <= 10) { alert('学生年龄不能小于10岁!'); return; } else if (this.StudentNewMessage.gender === '') { alert('学生性别不能为空!'); return; } else if (this.StudentNewMessage.address === '请选择' || this.StudentNewMessage.address === '') { alert('学生未选择地址!'); return; } else { //将新添加的学生信息添加到students数组中 this.students.push(this.StudentNewMessage); this.StudentNewMessage = {}; } }, // 按年龄排序 StuAgeEstimate() { this.students.sort((a, b) => { return a.age - b.age; }) }, // 删除学生信息 deleteStuMessage(index){ this.students.splice(index,1); }, // 按姓名搜索 StuSearch() { // 判断是否输入了学生姓名 if (this.StuNameSearch === '') { alert('请输入学生姓名!'); return; } else { // 遍历students数组,查找是否有符合条件的学生 for (let i = 0; i < this.students.length; i++) { if (this.students[i].stuName === this.StuNameSearch) { // 将符合条件的学生信息存储到一个新数组中 let stuSearch = []; stuSearch.push(this.students[i]); // 将符合条件的学生信息替换students数组 this.students = stuSearch; return; } } // 如果遍历完students数组后,没有符合条件的学生,则提示没有该学生 alert('没有该学生!'); } } } }).mount("#app"); </script> </body> </html>
|