版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/MMryyy/article/details/89477032
js实现搜索历史记录功能
首先我们来对比一下localStorage和sessionStorage:
localStorage生命周期是永久,这意味着除非用户显示在浏览器提供的UI上清除localStorage信息,否则这些信息将永远存在。
sessionStorage生命周期为当前窗口或标签页,一旦窗口或标签页被永久关闭了,那么所有通过sessionStorage存储的数据也就被清空了。
html
<div class="top">
<div class="f1">
<input type="text" class="input_top"/>
<span>取消</span>
</div>
</div>
<div class="history">
<div class="history_top" style="display: none;">
<span class="search">搜索历史</span>
<span class="del">删除历史</span>
</div>
<div class="contain">
<div class="fr"></div>
</div>
</div>
<style type="text/css">
.top{
background:whitesmoke;
line-height: 70px;
padding-left: 10px;
}
.input_top{
border-radius: 20px;
width: