当前位置:网站首页>【Es6】利用添加数据,筛选并传输至页面等多项功能实现案例
【Es6】利用添加数据,筛选并传输至页面等多项功能实现案例
2022-07-17 05:04:00 【共创splendid--与您携手】
强化案例:
用数组保存一组学生,每个学生的属性包含,姓名,分数,姓名和分数从页面input框获取,点击查询按钮,刷选出分数大于60的所有同学用数组保存一组学生,
css内容部分:
li{
list-style:none;
}
*{
margin:0px;
padding:0px;
}
#names{
width:600px;
height:100%;
margin:100px auto;
border:2px solid #FF0000;
padding:10px 10px;
font-size:20px;
background-color:green;
}
#add{
margin-right:50px;
}
input{
width:200px;
font-size: 20px;
}
HTML内容部分:
<div id="names">
姓名:<input type="text" id="add">
分数:<input type="text" id="taby">
<button id="btn">添加</button>
<p>学生信息:</p>
<ul id="student">
</ul>
<button id="btn1">查找及格的学生</button>
<p>及格学生如下:</p>
<ul id="td">
</ul>
</div>
js内容部分:
//获取所有的标签
let names = document.querySelector('#add');
let taby = document.querySelector('#taby');
let student =document.querySelector('#student');
let td= document.querySelector('#td');
let btn = document.querySelector('#btn');
let btn1 = document.querySelector('#btn1');
let str='';
// let obj={};
let arr=[];
//添加一个监听,并且设置成点击事件
btn.addEventListener('click',()=>{
//将用户输入的姓名及成绩包装成对象的形式传输到数组,并且依次排列
arr.push({"name":names.value,"scroe":taby.value});
//通过map加工,获取数组中的item值
str=arr.map((item)=>{
// 通过解构获取学生的姓名及成绩
const{name,scroe}=item;
//通过返回值,将上面的内容打印出来返回给str
return `<li>姓名:${name},成绩:${scroe}</li>`;
})
//将上面str的内容打印到页面
student.innerHTML=str
}).join( )
//添加一个监听,并且设置成点击事件
btn1.addEventListener('click',()=>{
//通过filter()筛选出满足条件的数据
let newArray= arr.filter(item=>item.scroe>60);
//定义一个连接字符串变量
let str1 = '';
//通过map加工,获取数组中的item值
str1=newArray.map(item =>{
// 通过解构获取学生的姓名及成绩
const {name,scroe}=item;
//通过返回值,将上面的内容打印出来返回给str1
return `<li>姓名:${name},成绩:${scroe}`;
})
//将上面str1的内容打印到页面
td.innerHTML=str1;
}).join( )
实现案例:

边栏推荐
- POC——DVWA‘s SQL Injection
- The code of yolov5 model for pest identification in Title A of the 10th Teddy cup data mining challenge (has been run through, original works, continuously updated)
- C语言初学者之初识代码专项练习
- C语言练习2
- ArcGIS Pro发布服务
- NoSQL overview
- [p5.js] simulated fireworks effect - interactive media design assignment
- Basic operations of index library operation
- Restclient operation document
- 【C语言—零基础第八课】循环结构与break continue
猜你喜欢
随机推荐
【Batch】批量删除中间文件夹-个人研究脚本
【C语言—零基础第六课】输入输出语句格式与复合语句
Some concepts of ES
泰迪杯A题完整版 优化更新(4/23)
solve [email protected] : `node install. Problems of js`
Word2Vec原理及应用与文章相似度(推荐系统方法)
基于SSM框架的考勤签到请假系统
基于RTX30显卡的ArcGIS Pro2.8深度学习环境配置
Logic of image uploading
ModerlArts第一次培训笔记
POC——DVWA‘s File Inclusion
POC——DVWA‘s XSS Reflected
Order system of middle office
PCA feature dimensionality reduction of machine learning + case practice
PyGame aircraft War 1.0 (step + window no response problem)
Microservice high concurrency service governance
Desensitization field example
用户管理-分页
Simply and quickly establish a pytorch environment yolov5 target detection model to run (super simple)
【2022第十届‘泰迪杯’挑战赛】A题:害虫识别完整版(大致思路。详细过程和代码以及结果csv在压缩包中)









