当前位置:网站首页>Query product cases - page rendering data
Query product cases - page rendering data
2022-07-03 01:50:00 【Blizzard front end】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style> table {
width: 400px; border: 1px solid #000; border-collapse: collapse; margin: 0 auto; } td, th {
border: 1px solid #000; text-align: center; } input {
width: 50px; } .search {
width: 600px; margin: 20px auto; } </style>
</head>
<body>
<div class="search">
Inquire according to the price : <input type="text" class="start"> - <input type="text" class="end"> <button class="search-price"> Search for </button> Query by commodity name : <input type="text" class="product"> <button class="search-pro"> Inquire about </button>
</div>
<table>
<thead>
<tr>
<th>id</th>
<th> The product name </th>
<th> Price </th>
</tr>
</thead>
<tbody>
<!-- Data rendering to tbody in -->
</tbody>
</table>
<script> // Use the new array method to manipulate data var data = [{
id: 1, pname: ' millet ', price: 3999 }, {
id: 2, pname: 'oppo', price: 999 }, {
id: 3, pname: ' glory ', price: 1299 }, {
id: 4, pname: ' Huawei ', price: 1999 }, ]; // 1. Get the corresponding element var tbody = document.querySelector('tbody'); var search_price = document.querySelector('.search-price'); var start = document.querySelector('.start'); var end = document.querySelector('.end'); var product = document.querySelector('.product'); var search_pro = document.querySelector('.search-pro'); setDate(data); // 2. Render the data to the page function setDate(mydata) {
// First empty the original tbody The data in it tbody.innerHTML = ''; mydata.forEach(function(value) {
// console.log(value); var tr = document.createElement('tr'); // First create a row for each array element , Append this line to tbody Go to of tr.innerHTML = '<td>' + value.id + '</td><td>' + value.pname + '</td><td>' + value.price + '</td>'; tbody.appendChild(tr); }); } // 3. Query goods by price // When we hit the button , We can filter the objects in the array according to our commodity price search_price.addEventListener('click', function() {
// alert(11); var newDate = data.filter(function(value) {
return value.price >= start.value && value.price <= end.value; }); console.log(newDate); // Render the filtered objects to the page setDate(newDate); }); // 4. Find products by product name // If you query the only element in the array , use some More appropriate , Because it finds this element , It's not a cycle , More efficient ] search_pro.addEventListener('click', function() {
var arr = []; data.some(function(value) {
if (value.pname === product.value) {
// console.log(value); arr.push(value); return true; // return It must be written after true } }); // Render the data to the page setDate(arr); }) </script>
</body>
</html>



some and forEach difference
<script>
var arr = ['red', 'green', 'blue', 'pink'];
// 1. forEach iteration Traverse
console.log('forEach:');
arr.forEach(function(value) {
if (value == 'green') {
console.log(' Found the element ');
return true; // stay forEach Inside return The iteration will not be terminated
}
console.log(11);
})
// If you query the only element in the array , use some More appropriate ,
console.log('some:');
arr.some(function(value) {
if (value == 'green') {
console.log(' Found the element ');
return true; // stay some Inside encounter return true Is to stop traversal Iteration is more efficient
}
console.log(11);
});
// arr.filter(function(value) {
// if (value == 'green') {
// console.log(' Found the element ');
// return true; // // filter Inside return The iteration will not be terminated
// }
// console.log(11);
// });
</script>

边栏推荐
- [technology development-23]: application of DSP in future converged networks
- 【数据挖掘】任务2:医学数据库MIMIC-III数据处理
- 【Camera专题】手把手撸一份驱动 到 点亮Camera
- 【QT】自定义控件的封装
- 并发编程的三大核心问题 -《深入理解高并发编程》
- PS去除水印详解
- 网络安全-openvas
- Take you ten days to easily complete the go micro service series (II)
- Uniapp component -uni notice bar notice bar
- 网络安全-DNS欺骗与钓鱼网站
猜你喜欢

After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
![[shutter] animation animation (animatedwidget animation use process | create animation controller | create animation | create animatedwidget animation component | animation operation)](/img/5e/1d451a820eadbd05112b41bd0bc7d6.gif)
[shutter] animation animation (animatedwidget animation use process | create animation controller | create animation | create animatedwidget animation component | animation operation)

Learn the five skills you need to master in cloud computing application development
![[error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)](/img/fd/d862412db43a641537fd67f7910741.jpg)
[error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)

PS remove watermark details

技术大佬准备就绪,话题C位由你决定

【数据挖掘】任务2:医学数据库MIMIC-III数据处理

mysql

树形结构数据的处理

STM32 - Application of external interrupt induction lamp
随机推荐
海量数据冷热分离方案与实践
Qtablewidget lazy load remaining memory, no card!
Learn the five skills you need to master in cloud computing application development
How is the mask effect achieved in the LPL ban/pick selection stage?
[shutter] animation animation (animatedbuilder animation use process | create animation controller | create animation | create components for animation | associate animation with components | animatio
[技术发展-23]:DSP在未来融合网络中的应用
网络安全-动态路由协议RIP
Network security - scan
Introduction to kotlin collaboration
英语常用词汇
小程序開發的部分功能
[data mining] task 4:20newsgroups clustering
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
[understanding of opportunity -36]: Guiguzi - flying clamp chapter - prevention against killing and bait
Take you ten days to easily complete the go micro service series (I)
传输层 TCP主要特点和TCP连接
mysql
[data mining] task 1: distance calculation
LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
[error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)