当前位置:网站首页>[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 :

边栏推荐
猜你喜欢

Asynchronous data SMS verification code

es6新增-运算符的扩展
![Travel data acquisition, data analysis and data mining [2022.5.30]](/img/d3/7222f852f8a8ba8cddc22a55d90fad.png)
Travel data acquisition, data analysis and data mining [2022.5.30]

Applet cloud development form submission and data acquisition in the page

Pygame:外星人入侵

Use of flask

Mysql database experiment training 6, data view (detailed)

租用服务器,以及部署在pycharm专业版上的pytorch环境训练yolov5模型教程服务器环境安装库文件:

【LeetCode——编程能力入门第一天】基本数据类型[在区间范围内统计奇数数目/去掉最低工资和最高工资后的工资平均值)

NVIDIA GeForce Experience登录报错:验证程序加载失败,请检查您的浏览器设置,例如广告拦截程序(解决办法)
随机推荐
基于cuda10.0的pytorch深度学习环境配置
<script>标签内容详解
使用js实现安居客二级菜单及(注意事项和问题点演示)完整版
使用Echars实现水滴状、环形图、分割图、堆叠、组织架构图、地图轮廓等图表
Installation and fast use of Mongo DB stand-alone version
学习C语言的第6天
多功能(实现)封装函数
User - registration / login
硬核结构体,暴力解读
Logic of image uploading
Travel data acquisition, data analysis and data mining [2022.5.30]
学习C语言的第五天
(精讲)Es6 剩余参数,ES6内置对象,模板字符串内容(详例宝典)及灵活运用项目的实战案例
Internship project 2 - Homepage configuration - my data module
C语言初学者之初识代码专项练习
数据可视化
es6新增-运算符的扩展
轮播图的两种方法及自动轮播
无重复字符的最长字串
实习项目3-更改所有者