国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

JS實現(xiàn)搜索功能頁面(可搜索,無需數(shù)據(jù)庫,無后端)

這篇具有很好參考價值的文章主要介紹了JS實現(xiàn)搜索功能頁面(可搜索,無需數(shù)據(jù)庫,無后端)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

很多剛學習前端的小伙伴想做一個搜索頁面,一看要做后端又要數(shù)據(jù)庫的可能就放棄了,這里給大家?guī)硪粋€不需要數(shù)據(jù)庫的,也可以使用的搜索功能頁面。網(wǎng)頁包含了3個功能:搜索框,類別選項,價格進度條。

JS實現(xiàn)搜索功能頁面(可搜索,無需數(shù)據(jù)庫,無后端)

搜索框是實時搜索的,而且做了不區(qū)分英語大小寫,也支持中文搜索。

JS實現(xiàn)搜索功能頁面(可搜索,無需數(shù)據(jù)庫,無后端)

?使用類別選項,篩選相應類別的手表。

JS實現(xiàn)搜索功能頁面(可搜索,無需數(shù)據(jù)庫,無后端)

?拉動價值進度條篩選相應價格的手表。

JS實現(xiàn)搜索功能頁面(可搜索,無需數(shù)據(jù)庫,無后端)

?filter.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" href="./filter.css"/>
		<title>Filter Project</title>

	</head>
	<body>
		<div class="container">
			<div class="leftMenu">
				<input type="text" placeholder="Search..." class="search" />
				<h1>Categories</h1>
				<div class="cats">
				</div>
				<h1>Maximum Price</h1>
				<div class="price">
					<input type="range" class="priceRange" />
					<span class="priceValue"></span>
				</div>
			</div>
			<div class="content">
				<div class="products">
					<div class="product">
						<img 
							src="https://m.media-amazon.com/images/I/71e04Q53xlL._AC_UY879_.jpg" 
							alt=""
						/>
						<span class="name">name</span>
						<span class="priceText">$44</span>
					</div>
				</div>
			</div>
		</div>
		
		<script src="./filter.js"></script>
	</body>
</html>

filter.css

body{
	
}

.container{
	display: flex;
	padding: 50px;
}

.leftMenu{
	flex: 1;
}

.search{
	padding: 10px;
	width: 200px;
	border: 1px solid gray;
}

h1{
	font-size: 30px;
	color: #555;
	font-weight: 300;
}

.cat{
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.cat{
	cursor: pointer;
	font-size: 20px;
	font-weight: 300;
	padding: 5px;
}


.content{
	flex: 4;
}

.products{
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
}

.product{
	width: 350px;
	display: flex;
	flex-direction: column;
	gap: 30px;
	align-items: center;
}

img{
	width: 150px;
	height: 250px;
	object-fit: contain;
}

.name{
	font-weight: 300;
}

filter.js文章來源地址http://www.zghlxwxcb.cn/news/detail-502925.html

const data = [
	{
		id: 1,
		name: "Invicta Men's Pro Diver",
		img: "https://m.media-amazon.com/images/I/71e04Q53xlL._AC_UY879_.jpg",
		price: 74,
		cat: "Dress",
	},
	{
		id: 2,
		name: "Timex Men's Expedition Scout",
		img: "https://m.media-amazon.com/images/I/91WvnZ1g40L._AC_UY879_.jpg",
		price: 62,
		cat: "Dress",
	},
	{
		id: 3,
		name: "Breitling Superocean Heritage",
		img: "https://m.media-amazon.com/images/I/61hGDiWBU8L._AC_UY879_.jpg",
		price: 40,
		cat: "Casual",
	},
	{
		id: 4,
		name: "Casio Classic Resin Strap",
		img: "https://m.media-amazon.com/images/I/51Nk5SEBARL._AC_UY879_.jpg",
		price: 200,
		cat: "Sport",
	},
	{
		id: 5,
		name: "Garmin Venu Smartwatch",
		img: "https://m.media-amazon.com/images/I/51kyjYuOZhL._AC_UY879_.jpg",
		price: 16,
		cat: "Luxury",
	},

];


const productsContainer = document.querySelector(".products")
const searchInput = document.querySelector(".search")
const categoriesContainer = document.querySelector(".cats")
const priceRange = document.querySelector(".priceRange")
const priceValue = document.querySelector(".priceValue")

const displayProducts = (filteredProducts) =>{
	productsContainer.innerHTML = filteredProducts.map(product=>
	`
	<div class="product">
		<img 
			src=${product.img} 
			alt=""
		/>
		<span class="name">${product.name}</span>
		<span class="priceText">$${product.price}</span>
	</div>
	`
	).join("");
};

displayProducts(data);

searchInput.addEventListener("keyup",(e) => {
	const value = e.target.value.toLowerCase();
	
	if(value){
		displayProducts(data.filter(item=> item.name.toLowerCase().indexOf(value) != -1))
	}else{
		displayProducts(data);
	}
	
});

const setCategories = () => {
	const allCats = data.map((item) => item.cat)
	const categories = ["All",
	...allCats.filter((item,i) => {
		return allCats.indexOf(item)===i
	})
	];
	
	categoriesContainer.innerHTML = categories.map(cat=>
	`
	<span class="cat">${cat}</span>
	
	`
	).join("");
	
	categoriesContainer.addEventListener("click",(e)=>{
		const selectedCat = e.target.textContent;
		selectedCat === "All" ? displayProducts(data) : displayProducts(data.filter(item=>
		item.cat === selectedCat));
	});
	
};

const setPrices = ()=>{
	const priceList = data.map((item) => item.price);
	const minPrice = Math.min(...priceList)
	const maxPrice = Math.max(...priceList)
	
	priceRange.min = minPrice
	priceRange.max = maxPrice
	priceRange.value = maxPrice
	priceValue.textContent = "$" + maxPrice
	
	priceRange.addEventListener("input",(e)=>{
		priceValue.textContent = "$" + e.target.value;
		displayProducts(data.filter((item) => item.price <= e.target.value));
	});
	
};

setCategories();
setPrices();

到了這里,關(guān)于JS實現(xiàn)搜索功能頁面(可搜索,無需數(shù)據(jù)庫,無后端)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • Springboot 實踐(7)springboot添加html頁面,實現(xiàn)數(shù)據(jù)庫數(shù)據(jù)的訪問

    Springboot 實踐(7)springboot添加html頁面,實現(xiàn)數(shù)據(jù)庫數(shù)據(jù)的訪問

    ????????前文講解,項目已經(jīng)實現(xiàn)了數(shù)據(jù)庫Dao數(shù)據(jù)接口,并通過spring security數(shù)據(jù)實現(xiàn)了對系統(tǒng)資源的保護。本文重點講解Dao數(shù)據(jù)接口頁面的實現(xiàn),其中涉及頁面導航欄、菜單欄及頁面信息欄3各部分。 1、創(chuàng)建html頁面 ????????前文講解中,資源目錄已經(jīng)建設完成,如圖

    2024年02月12日
    瀏覽(26)
  • arkTS開發(fā)鴻蒙OS應用(登錄頁面實現(xiàn),連接數(shù)據(jù)庫)

    arkTS開發(fā)鴻蒙OS應用(登錄頁面實現(xiàn),連接數(shù)據(jù)庫)

    喜歡的朋友可在抖音、小紅書、微信公眾號、嗶哩嗶哩搜索“淼學派對”。知乎搜索“編程淼”。

    2024年03月24日
    瀏覽(25)
  • Jeecg開發(fā)框架前端VUE2數(shù)據(jù)頁面與后端數(shù)據(jù)庫交互實現(xiàn)

    Jeecg開發(fā)框架前端VUE2數(shù)據(jù)頁面與后端數(shù)據(jù)庫交互實現(xiàn)

    ? JeecgBoot 是一款基于代碼生成器的 低代碼 開發(fā)平臺,零代碼開發(fā)!采用前后端分離架構(gòu):SpringBoot2.x,Ant DesignVue,Mybatis-plus,Shiro,JWT。強大的代碼生成器讓前后端代碼一鍵生成,無需寫任何代碼! JeecgBoot引領(lǐng)新的開發(fā)模式(Online Coding模式- 代碼生成器模式- 手工MERGE智能開發(fā)

    2024年02月11日
    瀏覽(50)
  • 只使用JS怎么給靜態(tài)頁面網(wǎng)站添加站內(nèi)全局搜索功能?

    只使用JS怎么給靜態(tài)頁面網(wǎng)站添加站內(nèi)全局搜索功能?

    ?? 個人網(wǎng)站:【 海擁】【神級代碼資源網(wǎng)站】【辦公神器】 ?? 基于Web端打造的:??輕量化工具創(chuàng)作平臺 ?? 想尋找共同學習交流的小伙伴,請點擊【全棧技術(shù)交流群】 靜態(tài)頁面通常由HTML、CSS 和 JavaScript 等靜態(tài)文件組成,這些文件在服務器上不會動態(tài)生成或修改,所以加

    2024年02月05日
    瀏覽(16)
  • Flutter框架實現(xiàn)登錄注冊功能,不連接數(shù)據(jù)庫

    要在Flutter框架中實現(xiàn)登錄和注冊功能,而不連接數(shù)據(jù)庫,可以使用本地存儲來存儲用戶信息。以下是一個簡單的示例,演示如何使用本地存儲來實現(xiàn)登錄和注冊功能。 首先,我們需要添加 shared_preferences 插件到 pubspec.yaml 文件中: 然后,在 lib 文件夾中創(chuàng)建一個新的文件夾

    2024年02月08日
    瀏覽(26)
  • JavaWeb05(刪除&增加&修改功能實現(xiàn)&連接數(shù)據(jù)庫)

    JavaWeb05(刪除&增加&修改功能實現(xiàn)&連接數(shù)據(jù)庫)

    目錄 一.實現(xiàn)刪除功能 1.1 url如何傳參? xx.do?參數(shù)=參數(shù)值參數(shù)名=參數(shù)值 1.2 servlet如何拿對應值? //根據(jù)參數(shù)名拿到對應的參數(shù)值? String str = req.getParameter(\\\"參數(shù)名\\\") 1.3 如何詢問? οnclick=\\\"return confirm(\\\'確定要刪除嘛?\\\')\\\" 1.4 代碼分析 1.4.1 前端傳參 刪除? 1.4.2 后臺業(yè)務處理 二.實

    2024年02月02日
    瀏覽(20)
  • MVC框架實現(xiàn)用戶登錄注冊功能(連接數(shù)據(jù)庫)

    MVC框架實現(xiàn)用戶登錄注冊功能(連接數(shù)據(jù)庫)

    一、簡單理解MVC框架 二、項目結(jié)構(gòu) 三、項目源碼 3.1 User 3.2?UserDao 3.3?RegisterDao 3.4?servletControll 3.5 servletControllRegister 3.6?web.xml 3.7?login.jsp 3.8?register.jsp 3.9?success.jsp 3.10?failure.jsp ?四、實現(xiàn)效果 總結(jié) 本篇文章主要介紹利用MVC框架去實現(xiàn)一個簡單的用戶登錄注冊功能,內(nèi)容主

    2024年02月06日
    瀏覽(38)
  • Node.js連接數(shù)據(jù)庫 實現(xiàn)注冊、登錄、判斷注冊

    Node.js連接數(shù)據(jù)庫 實現(xiàn)注冊、登錄、判斷注冊

    Node.js連接數(shù)據(jù)庫實現(xiàn)注冊,登錄,在登錄時檢測賬號是否進行注冊。 此創(chuàng)建文件夾可以不是使用Vue-cli進行創(chuàng)建,只是簡單創(chuàng)建文件夾便可。 使用npm進行mysql插件的安裝,cmd黑窗口運行下列指令 此指令運行完成,文件夾根目錄出現(xiàn) node_modules 文件 黑窗口運行 npm init 指令,出現(xiàn)

    2024年02月09日
    瀏覽(42)
  • quarkus數(shù)據(jù)庫篇之二:無需數(shù)據(jù)庫也能運行增刪改查(dev模式)

    quarkus數(shù)據(jù)庫篇之二:無需數(shù)據(jù)庫也能運行增刪改查(dev模式)

    這里分類和匯總了欣宸的全部原創(chuàng)(含配套源碼):https://github.com/zq2599/blog_demos 本篇內(nèi)容并非數(shù)據(jù)庫相關(guān)的核心知識,而是對一個實用工具的說明介紹,此工具在官方介紹中被稱為 Zero Config Setup (Dev Services) ,(零配置的設置,忒莫名其妙) 我這邊簡單總結(jié)為:如果你沒有數(shù)據(jù)

    2024年02月12日
    瀏覽(40)
  • Android開發(fā)----實現(xiàn)登錄注冊頁面(創(chuàng)建本地數(shù)據(jù)庫,對注冊的賬戶密碼進行存儲)

    Android開發(fā)----實現(xiàn)登錄注冊頁面(創(chuàng)建本地數(shù)據(jù)庫,對注冊的賬戶密碼進行存儲)

    寫在前面: 本文實現(xiàn)了登錄注冊頁面的開發(fā),創(chuàng)建了本地數(shù)據(jù)庫,存儲注冊的賬戶密碼。注冊賬戶為手機號,對賬戶為手機號進行了正則化驗證。登錄成功跳轉(zhuǎn)至主頁面。 20221028-實現(xiàn)登錄注冊功能 首先說一下,項目部署是在原有項目新建兩個activity( 項目右鍵–new–activi

    2024年02月03日
    瀏覽(28)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包