类别:企业动态 发布时间:2021-01-08 浏览人次:
“搜索”可以使我们更快的找到某一个关键词或者某一个商品,所以“模糊查询”和“下拉匹配”也成了前端必备的一个小技能,开门见山,希望对朋友们有帮助。
---搜索框模糊查询带下拉匹配效果html---
!------------搜索框模糊查询带下拉匹配效果html---------------------- div div form action="#" method="post" name="searchform" id="searchform" input type="text" id="tt" value="" plete="off" / p img src="img/search-1.png" alt="" /p p img src="img/camera.png" alt="" /p /li li img src="img/searchBtn.png" alt="" /li /ul /form /div /div
---搜索框模糊查询带下拉匹配效果-css---
.fl {float: left;} .fr {float: right;} .clearfix:after { content: ''; display: block; clear: both; visibility: hidden; height: 0; .clearfix { zoom: 1} .mar0 { margin: 0 auto;} .pos1 {position: relative;} input { border: none; outline: none; .w100 {width: 100%;} .gover_search{ width: 420px; position: relative; border-radius: 20px; height: 42px; border: 2px solid #fb6910; background:#fff; margin-top: 50px; margin-left: 90px; . ul{ list-style: none; .gover_search_form { height: 37px; width: 420px; position: relative; /*输入框*/ . .text{ margin: 0; width: 334px; height: 38px; outline: none; vertical-align: middle; float: left; padding-left: 27px; line-height: 40px; margin-left: 16px; /*搜索按钮*/ . .button { width: 120px; height: 40px; border: none; background-color: #4b140d; color: #fff; font-size: 19px; font-weight: bold; outline: none; float: left; /* !--隐藏的搜索框下拉列表-- */ .plete-layout{ position: absolute; z-index: 999; left: 0px; max-height: 260px; overflow-y: auto; overflow-x: hidden; top: 213px !important; width: 336px !important; border: 1px solid #ccc; border-top: none; display: none; color: #004080; background-color: #fff; .plete-layout table{ width:336px !important; .plete-layout table tr{ margin-bottom:5px !important; cursor:pointer; .plete-layout table tr td{ height: 25px !important; width: 336px !important; padding:0 10px !important; line-height: 25px !important; .plete-layout table tr:hover{ background-color:#fb6910 !important; color:#fff; .plete-layout table tr:hover td div{ color:#fff; .plete-layout table tr:hover td div span{ color:#fff; /*搜索框下拉列表关键字数量*/ .keyRightSpan{ float: right; display: block; width: auto; height: 25px !important; line-height: 25px !important; padding-right:8px background-color: #fff; /*关闭搜索框下拉列表按钮*/ .search { width: 22px; height: 22px; position: absolute; top: 9px; left: 12px; z-index: 2; .search img { width: 100%; height: 100%; .camera { width: 22px; height: 22px; position: absolute; top: 9px; right: 80px; z-index: 2; .camera img { width: 100%; height: 100%; .searchBtn { width: 70px; height: 40px; position: absolute; top: 0px; right: 0px; z-index: 2; .searchBtn img { width: 100%; height: 100%; }
因为是用了bootstrap框架,所以引入了bootstrap的样式,自我调整哈 link rel="stylesheet" href="css/bootstrap.css" rel="external nofollow"
样式写好以后就是js实现下来匹配了,plete.js的引入
script src="js/jquery-3.1.1.js" /script script src="js/index.js" /script script src="js/plete.js" /script
---搜索框模糊查询带下拉匹配效果-js---
// 隐藏的搜索框下拉列表 $(function () { var num = 0; $("#tt").plete({ width: 543, data: [{title: "牛栏山 span 约5个结果 /span ", result: {ff: "qq"}}, {title: "郎酒 span 约2个结果 /span "}, {title: "茅台 span 约4个结果 /span "}, {title: "五粮液 span 约2个结果 /span "}, {title: "水井坊 span 约7个结果 /span "}, {title: "汾酒 span 约3个结果 /span "}, {title: "洋府 span 约2个结果 /span "}, {title: "董酒 span 约5个结果 /span "}, {title: "剑南春 span 约2个结果 /span "}, {title: "劲酒 span 约8个结果 /span "}], callback: function (data) { console.log(data.title); })
接下来就是这个效果的截图
可以鼠标悬浮时选中某一个关键词,然后点击的时候把它的值(value)放在input框里
总结
以上所述是小编给大家介绍的JS实现模糊查询带下拉匹配效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对凡科网站的支持!
您的部位: > 新闻报道新闻资讯 > 企业网站建设 > 【上海市seo优化】那样才可以让百度搜索钟意你新的一年里seo优化该怎样做才能让百度搜索钟意你,在2018有许多朋友问网编,为何一些...
2021-01-12详细说明angularJs中自定directive的数据信息互动 本文关键详细介绍了详细说明angularJs中自定directive的数据信息互动,网编感觉挺好的,如今共享给大伙儿,也给大伙儿做下参照。一...
2021-01-12JavaScript自定文字框鼠标光标 文字框(input或textarea)的鼠标光标没法改动款式(除开根据color改动鼠标光标色调)。但小编期待本人建立自身的网站时,文字框的鼠标光标有归属于...
2021-01-12重要词:网站实行要求分析的压根数据信息总体目标 现有 13 人访问 为何要开展网站数据信息分析?1、立即把握网站实行的实际效果,减少盲目跟风性;2、分析各种各样互联网营销推广...
2021-01-12主题活动企业网站建设的要求 主题活动网站怎样反映特点,精准定位爱好群体? 主题活动网站怎样用品牌形象化的語言呈现商品的特点? 主题活动网站怎样吸引住潜在用户选购? 主题...
2021-01-12百度搜索惊雷优化算法不久不久,又接到了百度搜索搜狗引擎建网站提升市场研究报告。以便让众多网站站长充足掌握百度搜索检索模块标准,并依据标准有效安全性基本建设网站、提...
2021-01-12