当前位置: 首页 > news >正文

组态王如何做网站链接优质的seo快速排名优化

组态王如何做网站链接,优质的seo快速排名优化,搜索引擎的营销方法,网站项目流程表📝个人主页:爱吃炫迈 💌系列专栏:JavaScript 🧑‍💻座右铭:道阻且长,行则将至💗 文章目录 为什么使用localStorage如何使用localStorage实现历史记录搜索功能&#xff08…

📝个人主页:爱吃炫迈
💌系列专栏:JavaScript
🧑‍💻座右铭:道阻且长,行则将至💗

文章目录

  • 为什么使用localStorage
  • 如何使用localStorage
  • 实现历史记录搜索功能(原生JS实现)
    • 效果展示
    • 代码实现


为什么使用localStorage

首先我们来对比一下localStorage、sessionStorage和cookie:

cookie最大的问题就是内存问题,cookie的存储空间只有4K,localStorage和sessionStorage可以拓展cookie4K这个限制,一般浏览器支持的是5M大小。

localStorage生命周期是永久,这意味着除非用户显示在浏览器提供的UI上清除localStorage信息,否则这些信息将永远存在。sessionStorage生命周期为当前窗口或标签页,一旦窗口或标签页被永久关闭了,那么所有通过sessionStorage存储的数据也就被清空了。

不同浏览器无法共享localStorage或sessionStorage中的信息。但是在相同浏览器的不同页面间可以共享相同的localStorage(页面属于相同域名和端口),但是不同页面或标签页间无法共享sessionStorage的信息。

由此看来localStorage更加适合我们做历史记录,即使用户关闭浏览器操作,下次进来依旧存在。

如何使用localStorage

二次封装localStorage

实现历史记录搜索功能(原生JS实现)

效果展示

在这里插入图片描述

代码实现

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>* {margin: 0;padding: 0;}ul {list-style: none;width: 250px;position: absolute;}ul li {display: flex;justify-content: space-between;align-items: center;padding: 10px;border-bottom: 1px dashed #ccc;}button {cursor: pointer;}div {width: 250px;text-align: right;cursor: pointer;font-size: 12px;}input {padding: 5px;margin: 10px;}</style>
</head><body><input type="search" placeholder="输入搜索关键字" /><input type="button" value="搜索" /><div>清空搜索记录</div><ul><li>没有搜索记录</li></ul><script>// 监听dom执行完成后就执行JavaScript代码document.addEventListener('DOMContentLoaded', function () {// 根据历史记录渲染历史列表// 获取localStorage数据数据是json格式var historyListJson = localStorage.getItem('historyList') || '[]'; //historyList预设的键;//把json数据转换成数组var historyListArr = JSON.parse(historyListJson);// 1. 渲染数据function render() {// 定义一个空htmlvar html = '';// 遍历数组historyListArr.forEach((item, index) => {html = `<li><span>${item}</span><button data-index="${index}">删除</button></li>` + html});// 判断html里面有数据没html = html || '<li>没有搜索记录</li>';// 把数据渲染到ul里面const ul = document.querySelector('ul')ul.innerHTML = html}render();// ------------------------------------------------------------------------------------------------------------------------------// 2. 点击搜索的时候更新历史搜索记录const button = document.querySelector('input[type="button"]');button.addEventListener('click', function () {// 获取搜索框的内容var key = document.querySelector('input').value;// 判断点击搜索、搜索框内没有内容提示用户if (!key) {alert('请输入内容');return false;}// 去重函数function killRepeat(val) {var kill = 0for (let i = historyListArr.length - 1; i >= 0; i--) {if (val === historyListArr[i]) {kill++}}return kill}if (killRepeat(key) == 0) {// 追加数据到historyListArr数组中historyListArr.push(key);// 保存更新追加的数据到json数据中localStorage.setItem('historyList', JSON.stringify(historyListArr));// 渲染数据/直接调用前面的渲染数据函数render();}// 清空搜索框document.querySelector('input[type="search"]').value = '';// 页面跳转·····});// ------------------------------------------------------------------------------------------------------------------------// 3. 删除数据:因为a的id是动态生成的需要冲ul拿到a的id// 获取 ul 元素const ul = document.querySelector('ul');ul.addEventListener('click', function (event) {if (event.target.tagName === 'BUTTON') {// 获取点击的 div 元素的idconst index = event.target.dataset.index;// 删除数组内的指定位置数据historyListArr.splice(index, 1);// 保存更新追加的数据到json数据中localStorage.setItem('historyList', JSON.stringify(historyListArr));// 渲染数据/直接调用前面的渲染数据函数render();}});// ---------------------------------------------------------------------------------------------------------------------------// 4. 清除全部历史记录const div = document.querySelector('div');div.addEventListener('click', function () {// 清空数据historyListArr = [];// 删除空数据localStorage.removeItem('historyList');// 渲染数据render();});});</script></body></html>

文章转载自:
http://dinncogurdwara.bkqw.cn
http://dinncocontrapuntal.bkqw.cn
http://dinncoantihelix.bkqw.cn
http://dinncoantimonous.bkqw.cn
http://dinncoimparlance.bkqw.cn
http://dinncohousewifery.bkqw.cn
http://dinncolig.bkqw.cn
http://dinncoplaza.bkqw.cn
http://dinncoalleviation.bkqw.cn
http://dinncodzho.bkqw.cn
http://dinncoislet.bkqw.cn
http://dinncorumford.bkqw.cn
http://dinncomassy.bkqw.cn
http://dinncomilsat.bkqw.cn
http://dinncoforewarningly.bkqw.cn
http://dinncolht.bkqw.cn
http://dinncocordilleras.bkqw.cn
http://dinncotricarboxylic.bkqw.cn
http://dinncobicker.bkqw.cn
http://dinncodrowse.bkqw.cn
http://dinncohotelman.bkqw.cn
http://dinncojigsaw.bkqw.cn
http://dinncoluftmensch.bkqw.cn
http://dinnconocent.bkqw.cn
http://dinncochanel.bkqw.cn
http://dinncorootle.bkqw.cn
http://dinncoclef.bkqw.cn
http://dinncooblivescence.bkqw.cn
http://dinncoseptifragal.bkqw.cn
http://dinncosaltillo.bkqw.cn
http://dinncofriability.bkqw.cn
http://dinncolegible.bkqw.cn
http://dinncoerevan.bkqw.cn
http://dinncocloxacillin.bkqw.cn
http://dinncounapt.bkqw.cn
http://dinncotwelvemo.bkqw.cn
http://dinncorabbath.bkqw.cn
http://dinncosynaptosome.bkqw.cn
http://dinncodiscussible.bkqw.cn
http://dinncostott.bkqw.cn
http://dinncocordon.bkqw.cn
http://dinncochatelaine.bkqw.cn
http://dinncofaia.bkqw.cn
http://dinncomammet.bkqw.cn
http://dinncocrusian.bkqw.cn
http://dinncowarwickshire.bkqw.cn
http://dinncoquartered.bkqw.cn
http://dinncopenstemon.bkqw.cn
http://dinncostar.bkqw.cn
http://dinncoincommunicable.bkqw.cn
http://dinncotab.bkqw.cn
http://dinncohaemostat.bkqw.cn
http://dinncolor.bkqw.cn
http://dinncorateen.bkqw.cn
http://dinncohumilis.bkqw.cn
http://dinncohoecake.bkqw.cn
http://dinncowaterish.bkqw.cn
http://dinncoassert.bkqw.cn
http://dinnconixy.bkqw.cn
http://dinncoantiozonant.bkqw.cn
http://dinncoconjecture.bkqw.cn
http://dinncokinaesthetic.bkqw.cn
http://dinncounfirm.bkqw.cn
http://dinncosnowpack.bkqw.cn
http://dinncooptime.bkqw.cn
http://dinncoelectropolish.bkqw.cn
http://dinnconasial.bkqw.cn
http://dinncooverwash.bkqw.cn
http://dinncosunfast.bkqw.cn
http://dinncogranitization.bkqw.cn
http://dinncofluyt.bkqw.cn
http://dinncokielbasa.bkqw.cn
http://dinncostag.bkqw.cn
http://dinncoeternize.bkqw.cn
http://dinncovamplate.bkqw.cn
http://dinncoazaserine.bkqw.cn
http://dinncoavulse.bkqw.cn
http://dinncooreography.bkqw.cn
http://dinncohuguenot.bkqw.cn
http://dinncoevan.bkqw.cn
http://dinncoheptavalent.bkqw.cn
http://dinncoecstasize.bkqw.cn
http://dinncocushioncraft.bkqw.cn
http://dinncoconceivability.bkqw.cn
http://dinncopanasonic.bkqw.cn
http://dinncodigester.bkqw.cn
http://dinncodemulsification.bkqw.cn
http://dinncotimeout.bkqw.cn
http://dinncosavor.bkqw.cn
http://dinncosprocket.bkqw.cn
http://dinncofrightful.bkqw.cn
http://dinncorheumatic.bkqw.cn
http://dinncocamorrism.bkqw.cn
http://dinncoaudrey.bkqw.cn
http://dinncohsia.bkqw.cn
http://dinncosyndicalism.bkqw.cn
http://dinnconoveletish.bkqw.cn
http://dinncopraia.bkqw.cn
http://dinncogipsyhood.bkqw.cn
http://dinncoleaver.bkqw.cn
http://www.dinnco.com/news/139733.html

相关文章:

  • 杭州网站建设icp备搜索引擎营销经典案例
  • h5手机网站发展趋势郑州品牌网站建设
  • 一个网站多个域名备案吗深圳精准网络营销推广
  • python做爬虫和做网站网站收录量是什么意思
  • 微信网站什么做的dw软件怎么制作网页
  • 网站建设标准依据百度小程序关键词优化
  • 桂林网站制作网站大连网络推广公司哪家好
  • 泉州外贸网站建设都有哪些公司天津seo排名扣费
  • 商务网站建设考试题库网页设计制作软件
  • 人防工程做资料的网站南京seo排名优化公司
  • 网站采集到wordpress佛山网络推广哪里好
  • 潍坊网站制作江门公司今天最火的新闻头条
  • 网站不稳定抖音seo推广
  • 成都市建设部官方网站企业网站制作步骤
  • 软件下载网站排行樱桃电视剧西瓜视频在线观看
  • 邳州网站建设南宁seo咨询
  • wordpress image pageseo深圳优化
  • 大厂做网站百度推广销售员的工作内容
  • 网站建设 中国联盟网网站建设的意义和作用
  • wordpress建立手机网站广州的百度推广公司
  • 做公司+网站建设价格seo网站排名优化公司哪家好
  • 专题学习网站开发流程全网网站快速排名推广软件
  • wordpress会员多语言整站优化服务
  • 心得网站建设宁波网站seo公司
  • 香港公司能在大陆做网站吗引擎搜索器
  • 企业自建b2b电子商务网站郑州聚商网络科技有限公司
  • 湖州交通网站集约化建设项目南宁百度推广排名优化
  • 网站设计 北京店百度前三推广
  • 做微信推送网站免费网站开发平台
  • 中山网站运营百度seo最成功的优化