前端cookie记录搜索框的历史,在搜索框下面展示最近五条(多个页面的搜索框历史同步)

本文介绍如何利用前端cookie实现跨页面搜索框历史记录的同步。通过设置相同cookie名称和路径,确保多个页面的搜索历史保持一致。当用户进行搜索操作时,无论是点击搜索按钮还是按回车键,都会将搜索词保存到cookie中。页面加载时,历史记录会被隐藏,待用户触发时显示。
摘要由CSDN通过智能技术生成

 多个页面的搜索框历史同步只需设置cookie的名称和路径一致即可

.gz_search_tab {
    width: 900px;
    height: 60px;
    line-height: 60px;
    background: #FFF;
    border-radius: 0px 5px 5px 0;
    margin: 0px auto;
    box-shadow: 0 0 10px #999;
}
.gz_search_tab input[type="text"] {
    font-size: 16px;
    width: 730px;
    background: url(serach.png) left center no-repeat;
    height: 60px;
    line-height: 60px;
    border: 0;
    margin-left: 20px;
    text-indent: 40px;
    outline: none;
}
#showHistory{background:#f1f1f1; width: 776px; padding:0px 20px; line-height: 30px; position: absolute; left: 50%; margin-left: -450px;z-index: 99;}
#showHistory span{ font-size:16px; display: block;height: 38px;line-height: 38px;}
<script type="text/javascript" src="jquery-1.8.3.min"></script>
<script type="text/javascript" src="jquery.cooki
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值