本文实例为大家分享了JS实现带导航城市列表以及输入搜索功能展示的具体代码,供大家参考,具体内容如下
实现功能:
1.加载城市列表,并生成索引(没有该索引的城市则无索引)
2.点击索引滚动页面到对应索引城市第一个位置
3.输入搜索
分析:
1.加载城市很容易,生成对应的索引。
首先需要得到所有的城市,然后拿出城市的首字母,放入一个数组中,去重并排序,
得到无重复并有序的索引数组后加入到div中显示
2.根据索引进行页面滚动
需要给索引列表添加事件,由于锚点会在链接产生带#号的地址,以及页面会有刷动的效果,索引这里不使用锚点,
因此这里使用jquery或者js的方法进行页面自行滚动
3.进行搜索
首先对整个body内容进行检索,其次对城市列表里面的内容进行检索,查找具体位置,然后高亮显示以及通过添加class或者其它进行快速定位
其余的就是样式问题了。
效果图:
代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ include file="/WEB-INF/page/common/tablib.jsp"%>a:link,a:visited{ text-decoration:none; color: blue; } #float_zm { margin: 2% 2% 2% *; z-index: 90; width: 11%; height: 90%; right: 5px; position:fixed; } #city_div { padding: 0% 2% 2% 1%; width:100%; float: left; margin-top: 2%; } #float_table { right: 5%; top: 9%; position: fixed; height: 90%; text-align: center; color: blue; width:25%; } #float_table tr td{ text-align: right; } #data { width:100%; } #data tr td { border-bottom: 1px solid #e5e5e5; padding: 2% 1% 2% 1%; } #data tr td a{ width:100%; } .highlight { background: yellow; color: red; } #showSelectZm{ position:absolute; left:45%; top:40%; border:3px solid #B2D0F7; padding:10px; font:bold 14px verdana,tahoma,helvetica; color:#003366; width:8%; text-align:center; } #seachInput { width: 78%; } #folat_top_div { z-index: 93; padding-top: 3%; position: fixed; padding-left: 5%; width: 95%; height: 9%; background-color: #efefef; } #body_div { float: left; width: 100%; } .zhanwei_div { height: 9%; } .fade{ position:fixed; right:0; bottom:0; _position:absolute; _top:expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); } .formTips.fade { animation: 3s ease 0s normal both 1 running fade; } .fade { bottom: 0; position: fixed; right: 0; } .formTips { left: 0; position: absolute; text-align: center; width: 100%; z-index: 9999; } .formTips span { background: rgba(0, 0, 0, 0.6) none repeat scroll 0 0; border-radius: 5px; color: #fff; font-size: 14px; padding: 8px 10px; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



