当前位置: 首页 > 编程日记 > 正文

回忆之城市搜索

直接看效果点这里

HTML

<!DOCTYPE html>
<html>
<head lang="zh-CN"><meta charset="utf-8"><title> 城市搜索 </title><link rel="stylesheet" href="ui-departure.css">
</head>
<body>
<h2>热门+城市分组</h2>
<input class="test" type="text"/>
<input class="test" type="text"/>
<h2>热门+搜索</h2>
<input class="test2" type="text"/>
<h2>热门+搜索+城市分组</h2>
<input class="test3" type="text"/>
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
<script>// 所有城市数据var DEPARTURE_DATA = [{"name": "北京","code": "bj","pinyin": "beijing"}, {"name": "重庆","code": "cq","pinyin": "chongqing"}, {"name": "香港","code": "xg","pinyin": "xianggang"}, {"name": "广州","code": "gz","pinyin": "guangzhou"}, {"name": "昆明","code": "km","pinyin": "kunming"}, {"name": "大连","code": "dl","pinyin": "daliang"}, {"name": "天津","code": "tj","pinyin": "tianjing"}, {"name": "海口","code": "hk","pinyin": "haikou"}, {"name": "成都","code": "cd","pinyin": "chengdu"}, {"name": "澳门","code": "am","pinyin": "aomen"}];// 热门出发城市var DEPARTURE_HOT = [{"name": "全国","code": "qg"},{"name": "郑州","code": "zz"},{"name": "桂林","code": "gl"}];
</script>
<script src="jquery.ui-departure.js"></script>
<script>//热门+城市分组
    $(".test").each(function(){var $this = $(this);$this.Departure({"ID": "J_Departure1","city_hot": DEPARTURE_HOT,"city_data": DEPARTURE_DATA,"hot_callback": function($This){$this.val($This.html())},"city_callback": function($This){$this.val($This.html())},"search_callback": function($This){$this.val($This.html());}});});//热门+搜索
    $(".test2").each(function(){var $this = $(this);$this.Departure({"ID": "J_Departure2","isSearch": true,"isGroup": false,"city_hot": DEPARTURE_HOT,"city_data": DEPARTURE_DATA,"hot_callback": function($This){$this.val($This.html())},"city_callback": function($This){$this.val($This.html())},"search_callback": function($This){$this.val($This.html());}});});//热门+搜索+城市分组
    $(".test3").each(function(){var $this = $(this);$this.Departure({"ID": "J_Departure3","isSearch": true,"city_hot": DEPARTURE_HOT,"city_data": DEPARTURE_DATA,"hot_callback": function($This){$this.val($This.html())},"city_callback": function($This){$this.val($This.html())},"search_callback": function($This){$this.val($This.html());}});});
</script>
</body>
</html>
View Code

CSS

/*** @description: 出发地* @author: jununx@gmail.com* @update: 2014/11/30*/
/*reset*/
h3, dl, dt, dd, p, input { margin: 0; padding: 0; }
a { text-decoration: none; color: #333; cursor: pointer; }
a:hover,.ui-departure-search-result a:hover,.ui-departure-special { color: #f60; }
.ui-departure-hot a, .ui-departure-city a, .ui-departure-search-result a { white-space: nowrap; word-break: break-all; }/*ui-departure*/
.ui-departure { position: absolute; z-index: 9999; width: 380px; padding: 0 10px;  border: 1px #999 solid; background-color: #fff; color: #333; font: 12px/1.5 'simsun', arial, 'sans-serif'; }
.ul-departure-title { position: relative; height: 20px; line-height: 20px; font-weight: normal; color: #f60; padding: 5px 0 5px 10px; font-size: 12px; border-bottom: 1px #eee solid;  }
.ul-departure-close { position: absolute; top: 5px; right: 0; padding: 0 2px 0 3px; font-size: 14px; font-weight: bold; color: #bbb; }
.ui-departure-hot { padding: 5px; overflow: hidden; border-bottom: 1px #eee solid; line-height: 24px; }
.ui-departure-hot a { float: left; margin-right: 10px; }
.ui-departure-search { padding: 10px 0 10px 20px; background-color: #f9f9f9; color: #999; border-bottom: 1px #eee solid; }
.ui-departure-search-label { padding: 0 14px; line-height: 26px; }
.ui-departure-search-text { width: 180px; padding: 4px 5px 5px; border: 1px #ccc solid; font: 12px/15px arial, "sans-serif"; }
.ui-departure-search-result { display: none; line-height: 24px; padding: 10px 0 0 100px; }
.ui-departure-search-result a { margin-right: 10px; color: #39f; }
.ui-departure-city { line-height: 21px; }
.ui-departure-city dl { padding: 5px 0 5px 5px; overflow: hidden; }
.ui-departure-city dt,.ui-departure-city dd { float: left; }
.ui-departure-city dt { width: 45px; font-weight: bold; color: #fff; background-color: #7abdea; text-align: center; }
.ui-departure-city dd { width: 330px; }
.ui-departure-city a { float: left; margin-left: 10px; }
View Code

JS

/*** @description: 出发地* @author: jununx@gmail.com* @update: 2014/11/30** @param {string}      ID                  给这个控件一个ID,默认自动生成,重绘避免重复生成,如果本页出现多次该控件最好填写不同的ID* @param {json}        city_hot            热门城市数据* @param {json}        city_data           需要分组的城市列表数据* @param {function}    hot_callback        点击热门城市的回调,参数返回当前对象* @param {function}    city_callback       点击所有城市的回调,参数返回当前对象* @param {function}    search_callback     搜索城市点击的回调,参数返回当前对象* @param {bool}        isGroup             是否显示分组(默认true)* @param {bool}        isSearch            是否显示搜索(默认false)*/;(function($){var methods = {init: function(options){var This = this, box_html = '';this.click(function(){// 一个页面有多个该控件时先隐藏其他的$('.ui-departure').hide();var box = $('#'+options.ID);if(!box.length){box = methods.createDeparture(options);$('body').append(box);}else{box.show();}box_html = methods.createDepartureTitle(options) + methods.createHotCity(options);if(options.isSearch){box_html += methods.createSearch();}if(options.isGroup){box_html += methods.createCityItems(options);}box.css({"top": This.offset().top + This.outerHeight(),"left": This.offset().left}).html(box_html);methods.bindEvent(options);return false;});},createDeparture: function(options){var res = $('<div id="'+options.ID+'" class="ui-departure"></div>');return res;},createDepartureTitle: function(){return '<h3 class="ul-departure-title">热门出发城市<a class="ul-departure-close">×</a></h3>';},createHotCity: function(options){var res = ['<div class="ui-departure-hot">'], city_hot = options.city_hot;for (var i = 0, len = city_hot.length; i < len; i++) {if(city_hot[i].name == '全国'){res.push('<a class="ui-departure-special">'+ city_hot[i].name +'</a>');}else {res.push('<a>'+ city_hot[i].name +'</a>');}}res.push('</div>');return res.join('');},createCityItems: function(options){var res = ['<div class="ui-departure-city">'],city_group = {"A-G": [],"H-L": [],"M-T": [],"W-Z": []},city_data = options.city_data;// 城市分组for (var i = 0, len = city_data.length; i < len; i++) {if (/^[abcdefg]/.test(city_data[i].code.toLowerCase())){city_group['A-G'].push('<a>'+ city_data[i].name +'</a>');}else if (/^[hijkl]/.test(city_data[i].code.toLowerCase())){city_group['H-L'].push('<a>'+ city_data[i].name +'</a>');}else if (/^[mnopqrst]/.test(city_data[i].code.toLowerCase())){city_group['M-T'].push('<a>'+ city_data[i].name +'</a>');}else if (/^[wxyz]/.test(city_data[i].code.toLowerCase())){city_group['W-Z'].push('<a>'+ city_data[i].name +'</a>');}}for (var n in city_group) {if(city_group[n].length){res.push('<dl><dt>'+n+'</dt>');res.push('<dd>'+city_group[n].join('')+'</dd>');res.push('</dl>');}}res.push('</div>');return res.join('');},createSearch: function(){var res = ['<div class="ui-departure-search">','<label class="ui-departure-search-label">输入出发城市</label>','<input class="ui-departure-search-text" type="text"/>','<div class="ui-departure-search-result">','</div>','</div>'];return res.join('');},/*** 在城市数据里查找符合val的城市* @param data      {object}  特定格式* @param val       {string}* @param maxLen    {number}  返回的数组最多几项** @return {array} 返回符合条件的数组*/searchCity: function(data, val, maxLen){var res = [], city_data = data, thisVal = $.trim(val);for (var i = 0, len = city_data.length; i < len; i++) {if((/^[\u4e00-\u9fa5]+$/.test(thisVal) && city_data[i].name.indexOf(thisVal) === 0) ||(/^[a-zA-Z]+$/.test(thisVal) && city_data[i].code.indexOf(thisVal) === 0) ||(/^[a-zA-Z]+$/.test(thisVal) && city_data[i].pinyin.indexOf(thisVal) === 0)){res.push(city_data[i].name);if(res.length >= maxLen) {break;}}}return res;},bindEvent: function(options){var box = $('#'+options.ID);box// close.find(".ul-departure-close").click(function(){box.hide();}).end()// hot city callback.find(".ui-departure-hot a").click(function(){options.hot_callback($(this));box.hide();}).end()// search city.find(".ui-departure-search-text").keyup(function(){var thisVal = $(this).val(), searchResultCity = methods.searchCity(options.city_data, thisVal, 2);if(searchResultCity.length){box.find('.ui-departure-search-result').html('<a>'+ searchResultCity.join('</a><a>') +'</a>').find('a').click(function(){options.search_callback($(this));box.hide();}).end().show();}else{if(thisVal == ''){box.find('.ui-departure-search-result').hide();}else{box.find('.ui-departure-search-result').text('亲,暂时无搜索结果').show();}}}).end()// city callback.find(".ui-departure-city a").click(function(){options.city_callback($(this));box.hide();});// document close$(document).click(function(e){if($(e.target).attr('id') != options.ID && !$(e.target).parents('#'+options.ID).length){box.hide();}});}};$.fn.Departure = function(options){options = $.extend({"ID": "J_Departure"+Math.floor(new Date().getTime()),"isGroup": true,"isSearch": false,"city_hot": [],"city_data": [],"hot_callback": function(){},"city_callback": function(){},"search_callback": function(){}}, options || {});return this.each(function(){methods.init.call($(this), options);});};})(jQuery);

转载于:https://www.cnblogs.com/jununx/p/4472912.html

相关文章:

ATL::CStringA和std::string之间转换的一些误区

对于刚做windows下VC的开发同学&#xff0c;类型转换应该是一个令其很苦恼的问题。我刚写工作的时候&#xff0c;也为这类问题不停的在网上搜索转换方法。最近工作中遇到一个“神奇”的bug&#xff08;一般“神奇”的问题往往是低级错误导致的&#xff09;&#xff0c;最后跟踪…

Windows XP鲜为人知的70招

一、Windows XP优化恢复Windows经典界面很多人安装了Windows XP后的第一感觉就是Windows变得漂亮极了。只是可惜美丽的代价要耗掉我们本就不富裕的内存和显存。要想恢复到和经典Windows类似的界面和使用习惯&#xff0c;请在桌面上单击鼠标右键&#xff0c;选择“属性”命令即可…

Github开源趋势榜Top 1:英伟达升级发布二代StyleGAN,效果更完美

整理 | Jane出品 | AI科技大本营&#xff08;ID&#xff1a;rgznai100&#xff09;2018 年底&#xff0c;英伟达借鉴风格迁移的思路&#xff0c;提出当时最先进的无条件生成模型—— StyleGAN &#xff0c;吸引了大家广泛关注。随后&#xff0c;代码开源&#xff0c;一位 Uber …

百度地图 ip查询 service

官方文档&#xff1a;http://developer.baidu.com/map/wiki/index.php?titlewebapi/ip-api 请求 一个例子&#xff1a; http://api.map.baidu.com/location/ip?ak3GFi2F04wXaVuwmGu8fN49kL1234567890&ip180.161.128.181 返回 {"address": "CN|\u6cb3\u535…

python3编写简易统计服务器

打点这个功能总是美其名曰“帮助提升用户体验”&#xff0c;其实说白了就是记录用户做了哪些操作。目前国内很多通用软件都做了相关功能&#xff0c;像360、QQ等这样的以用户体验出众的软件&#xff0c;其打点的面自然也很广很细。当然这种“侵犯”用户隐私的事情在业内各个公司…

作价20亿美元!英特尔收购以色列AI芯片公司Habana Labs

出品 | AI科技大本营&#xff08;ID:rgznai1000&#xff09;12月16日&#xff0c;英特尔宣布以约 20 亿美元收购以色列公司Habana Labs&#xff0c;这成为英特尔在以色列仅次于 Mobileye&#xff08;153 亿美元&#xff09; 的第二大收购案。Habana Labs 成立于 2016 年&#x…

这就是奇客文化?简直太有才了!

这就是奇客文化&#xff1f;简直太有才了……

java中的char类型

2019独角兽企业重金招聘Python工程师标准>>> 一&#xff1a;char的初始化 char是Java中的保留字&#xff0c;与别的语言不同的是&#xff0c;char在Java中是16位的&#xff0c;因为Java用的是Unicode。不过8位的ASCII码包含在Unicode中&#xff0c;是从0~127的。 Ja…

[原创] 如何追踪每一笔记录的来龙去脉:一个完整的Audit Logging解决方案—Part I...

一、提出问题 在开发一个企业级 应用的时候&#xff0c;尤其在一个涉及到敏感数据的应用&#xff0c;比如财务系统、物流系统&#xff0c;我们往往有这样的需求&#xff1a;对于数据库中每一笔数据的添加、修改和删除&#xff0c;都需要有一个明确的日志&#xff0c;以便我们可…

进程间通信:同步双工管道

因为工作需要&#xff0c;需要设计出一个双工的IPC。&#xff08;转载请指明出处&#xff09;在一番比较后&#xff0c;我发现管道是比较符合我们的需求的。但是我们需求要求管道的对方是可信任的&#xff0c;而在vista以下系统是没有GetNamedPipeClientProcessId、GetNamedPip…

就因为一个笔记本,运营和产品吵得不可开交......

上班最讨厌的一件事情&#xff0c;莫过于开会&#xff0c;因为每次开会感觉就要吵架&#xff0c;这个今天开会又吵架了&#xff0c;吵架竟然是因为产品小姐姐的笔记本。产品小姐姐用了一本可擦笔记本记录会议内容&#xff0c;运营小姐姐竟然说这个本子有什么用&#xff0c;不就…

Ka的递归编程练习 Part4|Hanoi汉诺塔,双色汉诺塔的也有

1 #include <stdio.h>2 void hanoi(int s,char a,char b,char c) //a是出发盘&#xff0c;b是中途盘&#xff0c;c是结束盘 3 {4 if(s0) return;5 hanoi(s-1,a,c,b); //把最底下的从a借助c移动到b6 printf("%d from %c move to %c\n",s,a,c);7 …

一种精确从文本中提取URL的思路及实现

在今年三四月份&#xff0c;我接受了一个需求&#xff1a;从文本中提取URL。这样的需求&#xff0c;可能算是非常小众的需求了。大概只有QQ、飞信、阿里旺旺等之类的即时通讯软件存在这样的需求。在研究这个之前&#xff0c;我测试了这些软件这块功能&#xff0c;发现它们这块的…

解读 | 2019年10篇计算机视觉精选论文(上)

作者 | 神经小兮来源 | HyperAI超神经&#xff08;ID:HyperAI&#xff09;2019 年转眼已经接近尾声&#xff0c;我们看到&#xff0c;这一年计算机视觉&#xff08;CV&#xff09;领域又诞生了大量出色的论文&#xff0c;提出了许多新颖的架构和方法&#xff0c;进一步提高了视…

不错的工具:Reflector for .NET

下载地址: http://www.aisto.com/roeder/dotnet/ 注意&#xff1a;下载时要输一些注册信息&#xff0c;输入用户名时&#xff0c;中间要加一个空格。

Possible MySQL server UUID duplication for server

&#xfeff;&#xfeff;在mysql enterprise monitor监控过程中出现这样的event事件&#xff0c;Topic: Possible MySQL server UUID duplication for server 事件&#xff0c;从该提示的描述来看貌似是存在重复的uuid&#xff0c;而实际上主从关系并不存在重复的uuid。主从关…

使用VC实现一个“智能”自增减线程池

工作中接手了一款产品的改造。因为该产品可能使用很多线程&#xff0c;所以产品中使用了线程池。&#xff08;转载请指明来自BreakSoftware的CSDN博客&#xff09; 线程池的一个优点是降低线程创建和销毁的频率&#xff1b;缺点是可能在比较闲的时候还存在一定数量的空闲线程。…

国内外财务软件科目结构的比较

科目结构是整个会计核算的基础。国内外财务软件都是任意定义科目的分段及科目编码长度&#xff0c;一般都能支持六段到九段。但科目结构在不同的国家有不同的规范&#xff0c;因而在不同的财务软件中也就有不同的控制。在科目分类上&#xff0c;国内外有明显的区别。国外财务软…

朋友圈装死,微博蹦迪,Python教你如何掌握女神情绪变化 | CSDN博文精选

作者 | A字头来源 | 数据札记倌很多人都是在朋友圈装死&#xff0c;微博上蹦迪。微信朋友圈已经不是一个可以随意发表心情的地方了&#xff0c;微博才是&#xff01;所以你不要傻傻盯着女神的朋友圈发呆啦&#xff01;本文教你如何用Python自动通知女神微博情绪变化&#xff0c…

java异常笔记

Throwable是所有Java程序中错误处理的父类&#xff0c;有两种资类&#xff1a;Error和Exception。Error&#xff1a;表示由JVM所侦测到的无法预期的错误&#xff0c;由于这是属于JVM层次的严重错误&#xff0c;导致JVM无法继续执行&#xff0c;因此&#xff0c;这是不可捕捉到的…

2019最新进展 | Transformer在深度推荐系统中的应用

作者 | Alex-zhai来源 | 深度传送门&#xff08;ID:deep_deliver&#xff09;【导读】最近基于Transformer的一些NLP模型很火&#xff08;比如BERT&#xff0c;GPT-2等&#xff09;&#xff0c;因此将Transformer模型引入到推荐算法中是近期的一个潮流。Transformer比起传统的L…

自己架设windows升级服务器

大部分对计算机比较熟悉的朋友都知道&#xff0c;通常安装好Windows 操作系统后要做的第一件事就是上Windows Update网站去给Windows 安装补丁程序&#xff0c;否则各种漏洞对系统就是一个很大的威胁。不过遗憾的是很多人还没有这样的意识&#xff0c;疏忽了给系统打补丁。这也…

内嵌IE网页窗口中消除IE默认脚本设置影响的方法

随着人们对客户端软件界面要求的不断提高,软件开发商面临着一个问题:如何快速廉价开发出各种丰富效果的UI界面。设计出一套丰富控件的界面库是不容易的,且产品经理丰富的想法和UED对效果的追求,往往会使程序员疲于编写这些“效果控件”。目前市面上使用的很多界面库是基于X…

win7 64位操作系统中 Oracle 11g 安装教程(图解)

1.下载Oracle 11g R2 for Windows版本&#xff0c;下载地址如下  官方网站&#xff1a;  http://download.oracle.com/otn/nt/oracle11g/112010/win32_11gR2_database_1of2.zip http://download.oracle.com/otn/nt/oracle11g/112010/win32_11gR2_database_2of2.zip 2.解压两…

使用APIHOOK实现进程隐藏

今天翻出一些今年前写的代码。其中一个是09年&#xff0c;我帮一个读研的同学写的一个“无公害恶意”程序。大致要求就是要实现自启动和自我隐藏。我使用的都是些简单的技术&#xff0c;只是实现自我隐藏稍微让我花费了点时间写算法。其实这个算法也很简单&#xff0c;就是大学…

程序员创业前要做哪些准备?

作者 | hsm_computer出品 | CSDN博客在互联网时代&#xff0c;不少干IT的人白手起家&#xff0c;在短短的几年里通过努力干出了一番事业&#xff0c;有房有车有公司&#xff0c;在人前也很光鲜。这就吸引了更多的程序员想要通过自主创业来实现财务自由。殊不知&#xff0c;创业…

Flex编码过程

Flex编码过程当我们开发一个Flex程序&#xff0c;我们重复其他类型网络程序的过程&#xff0c;例如HTML,JSP,ASP和CFML。创建一个有用的Flex程序是很容易的&#xff1a;打开我们最喜欢的文本编辑器&#xff0c;例如Flex Builder&#xff0c;输入XML标签&#xff0c;编译成为SWF…

BufferedWriter

package JBJADV003;import java.io.*;public class BufferedWriterTest { public static void main(String[] args) { try { //创建一个FileWriter 对象 FileWriter fwnew FileWriter("c:\\myDoc\\hello.txt"); //创建一个BufferedWriter 对象 BufferedWriter bwnew…

使用VC内嵌Python实现的一个代码检测工具

最近组内准备整顿代码&#xff0c;领导让我写个简单的python脚本分析代码中注释的行数和无效注释。因为这个需求不是很急&#xff0c;所以我想把简单的事情做复杂点。于是就写了一个用VC内嵌Python&#xff0c;并通过模拟按键和发消息去控制其他软件的工具。&#xff08;转载请…

Python如何实现24个微信大群万人同步转发直播?

作者 | 猪哥66来源 | CSDN博客今天我们来学习微信机器人多群转发做同步图文直播&#xff01;一、背景介绍猪哥一年前在建Python学习群的时候就说过&#xff0c;要邀请企业大佬来学习群做直播。其实文章早就写好了&#xff0c;但是一直没有找到好的转发软件&#xff0c;所以耽搁…