当前位置:网站首页>[ES6] use multiple functions such as adding data, filtering and transmitting to the page to realize cases
[ES6] use multiple functions such as adding data, filtering and transmitting to the page to realize cases
2022-07-19 05:13:00 【Create splendid -- hand in hand with you】
Strengthen the case :
Save a group of students with an array , The attributes of each student include , full name , fraction , Names and scores from the page input Box acquisition , Click query button , Brush selection score is greater than 60 All the students in the class save a group of students in an array ,
css The content part :
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 The content part :
<div id="names">
full name :<input type="text" id="add">
fraction :<input type="text" id="taby">
<button id="btn"> add to </button>
<p> Student information :</p>
<ul id="student">
</ul>
<button id="btn1"> Find qualified students </button>
<p> The passing students are as follows :</p>
<ul id="td">
</ul>
</div>
js The content part :
// Get all the tags
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=[];
// Add a monitor , And set it as a click event
btn.addEventListener('click',()=>{
// The names and grades entered by the user are wrapped into objects and transferred to the array , And arranged in order
arr.push({"name":names.value,"scroe":taby.value});
// adopt map machining , Get... In the array item value
str=arr.map((item)=>{
// Get students' names and grades through deconstruction
const{name,scroe}=item;
// By return value , Print out the above content and return it to str
return `<li> full name :${name}, achievement :${scroe}</li>`;
})
// The above str Print the contents of to the page
student.innerHTML=str
}).join( )
// Add a monitor , And set it as a click event
btn1.addEventListener('click',()=>{
// adopt filter() Filter out the data that meets the conditions
let newArray= arr.filter(item=>item.scroe>60);
// Define a connection string variable
let str1 = '';
// adopt map machining , Get... In the array item value
str1=newArray.map(item =>{
// Get students' names and grades through deconstruction
const {name,scroe}=item;
// By return value , Print out the above content and return it to str1
return `<li> full name :${name}, achievement :${scroe}`;
})
// The above str1 Print the contents of to the page
td.innerHTML=str1;
}).join( )
Implement case :
边栏推荐
猜你喜欢
Travel data acquisition, data analysis and data mining [2022.5.30]
小程序云开发 上传图片到云存储
Internship project 1 - personalized homepage configuration
NVIDIA GeForce Experience登录报错:验证程序加载失败,请检查您的浏览器设置,例如广告拦截程序(解决办法)
模拟库函数
C语言初学者之初识代码专项练习
父组件加scoped有时也会影响子组件
[2022 10th Teddy Cup Challenge] Title A: complete version of pest identification (general idea. Detailed process and code and results CSV in compressed package)
C语言 带你 手撕 通讯录
ThreadLocal thread safety example and its principle
随机推荐
IDL调用6S大气校正
MySQL optimization
Bi design: distributed high concurrency epidemic prevention health management system based on vue+socket+redis
The principle and local storage of the throttle valve of the rotation chart are summarized
About the current response, the method getoutputstream() has been called
uni-app 条件编译#ifdef #endif 兼容多个终端
简单快速建立pytorch环境YOLOv5目标检测 模型跑起来(超简单)
STL容器——queue与deque的基本操作
【C语言—零基础第八课】循环结构与break continue
父组件加scoped有时也会影响子组件
轮播图的两种方法及自动轮播
Use echars to realize water drop, ring, segmentation, stacking, organization chart, map outline and other charts
Pygame:外星人入侵
一个问题的探讨
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)
Internship project 1 - personalized homepage configuration
百度地图 实现 热力图
小程序editor富文本编辑使用及rich-text解析富文本
学习C语言的第6天
多功能(实现)封装函数