C++:计算vector的和

问题

很简单的一个问题.
如下:

  1. 编写程序处理一个vector,其元素都表示整形值,计算vector中所有元素的和.
  2. 修改程序,使之计算表示浮点值的string之和.

C++.
image-2079

源代码


/*************************************************************************
> File Name: test.9.50.cpp
> Author: puruidong
> Mail: 1@w1520.com
> Created Time: 2014年05月29日
************************************************************************/

#include
#include
#include
#include
using namespace std;

/*******************************

编写程序处理一个vector,其元素都表示整形值,计算vector中所有元素的和.修改程序,使之计算表示浮点值的string之和.

***********************************/
int main()
{
vector vec;
vec.push_back("100.5");
vec.push_back("50.5");
vec.push_back("20.5");
vec.push_back("10.2");
double count(0);
for(vector::iterator it=vec.begin();it!=vec.end();++it)
{
count+=stod(*it);
}
cout << count << endl; //下面是第二个问题. vector vedou;
vedou.push_back(10.5);
vedou.push_back(15.7);
vedou.push_back(12.3);
vedou.push_back(20.5);
double countds(0);
string countcds ;
for(vector::iterator itdou=vedou.begin();itdou!=vedou.end();++itdou)
{
countds+=(*itdou);
//countcds=to_string(countds);
}
cout << "下面是计算表示浮点值的string之和:" << endl; countcds=to_string(countds); cout << countcds << endl; return 0; }

C++:vector初始化string

两个问题

  1. 编写程序,从一个vector初始化一个string.
  2. 假定你希望每次读取一个字符存入一个string中,而且知道最少需要读取100个字符,应该如何提高程序的性能.

C++.
image-2077

源码1


/*************************************************************************
> File Name: test.9.41.cpp
> Author: puruidong
> Mail: 1@w1520.com
> Created Time: 2014年05月25日 星期日
************************************************************************/

#include
#include
#include
using namespace std;

int main()
{
vector vec;
vec.push_back('h');
vec.push_back('e');
vec.push_back('l');
vec.push_back('l');
vec.push_back('o');
string s(vec.begin(),vec.end());
cout << s << endl; return 0; }

源码2


/*************************************************************************
> File Name: test.9.42.cpp
> Author: puruidong
> Mail: 1@w1520.com
> Created Time: 2014年05月25日 星期日
************************************************************************/
#include
#include

using namespace std;

int main()
{
char s;
vector vec;
cout << "输入单个字母:" << endl; while(cin >> s)
{
vec.push_back(s);
}
string sa(vec.begin(),vec.end());
cout << sa << endl; return 0; }

jQuery:选择省输出相应市

说明下

部分资料来自网络,有修改.[原文]
只有全国市,具体效果如下:

html效果图
image-2066

源码

在chrome下测试通过.










C++:新概念!获取你想知道的!!

标题说明

标题党了.这次遇到的是capacity,可以获取vector和string不重新分配内存空间的话,当前容器可以保存多少元素.

不重新分配内存空间,当前容器可以保存多少元素,这个概念很重要。看图:

c++ capacity
image-2059

题目

解释下面的程序片段做了什么:


vector svec;
svec.reserve(1024);//1
string word;
while(cin >> word)//2
{
svec.push_back(word);
}
svec.resize(svec.size()+svec.size()/2);//3
//下面这句是新添加的,可以猜一下输出结果.
cout << "svec.size():" << svec.size() << endl;//4 cout << "svec.size():" << svec.capacity() << endl;//5

源码及解答

解答:

  • 在[1]这个地方为vector分配最少1024个空间
  • 在[2]添加元素,假如添加的元素个数是n[看下面,添加数量不一定.]个
  • 在[3]这个地方对容器的大小进行调整

可以猜一下在上面[4]和[5]要输出的值.【capacity的值完全依赖于实现,因此可能有所差异.及以下运行结果来自:gcc 4.8.2版本.】

源码1

添加数量为256个元素.


/*************************************************************************
> File Name: test.9.39.cpp
> Author: puruidong
> Mail: 1@w1520.com
> Created Time: 2014年05月22日 星期四
************************************************************************/

#include
#include
using namespace std;

int main()
{
/*

解释下面的程序片段做了什么?
1.要求系统分配一个1024大小的空间;
2.向vector中添加256个元素;
3.缩小元素空间,vector中的实际元素是256个,由于除法是优先运算的,
因此3的运算结果大致是256+256/2=384

*/
vector svec;
svec.reserve(1024);//1
//while(cin >> word)
for(unsigned i=0;i!=256;++i)//2
{
svec.push_back(i+"test");
}
svec.resize(svec.size()+svec.size()/2);//3
cout << "test>>" << svec.size() << endl; cout << "capacity>>" << svec.capacity() << endl;//此行输出依赖具体实现,我测试输出为1024. return 0; }

c++ running
image-2060

源码2


/*************************************************************************
> File Name: test.9.39.cpp
> Author: puruidong
> Mail: 1@w1520.com
> Created Time: 2014年05月22日 星期四
************************************************************************/

#include
#include
using namespace std;

int main()
{
/*

解释下面的程序片段做了什么?
1.要求系统分配一个1024大小的空间;
2.向vector中添加512个元素;
3.缩小元素空间,vector中的实际元素是512个,由于除法是优先运算的,
因此3的运算结果大致是512+512/2=768.
capacity的输出是1024[未超过预先设置的空间容量].

*/
vector svec;
svec.reserve(1024);//1
//while(cin >> word)
for(unsigned i=0;i!=512;++i)//2
{
svec.push_back(i+"test");
}
svec.resize(svec.size()+svec.size()/2);//3(512+512/2)
cout << "test>>" << svec.size() << endl; cout << "capacity>>" << svec.capacity() << endl;//输出结果依赖具体实现,此处输出1024. return 0; }

C++.
image-2061

源码3

源码1和2有一个共同的特点,[3]的结算结果均未超过1024.下面的会有变化.

/*************************************************************************
> File Name: test.9.39.cpp
> Author: puruidong
> Mail: 1@w1520.com
> Created Time: 2014年05月22日 星期四
************************************************************************/

#include
#include
using namespace std;

int main()
{
/*

解释下面的程序片段做了什么?
1.要求系统分配一个1024大小的空间;
2.向vector中添加1000个元素;
3.缩小元素空间,vector中的实际元素是1000个,由于除法是优先运算的,
因此3的运算结果大致是(1000+500)=1500.
4.容器长度未超出1024时,为1024.{超过则会新分配空间,具体依赖实现.}

*/
vector svec;
svec.reserve(1024);//1
//while(cin >> word)
for(unsigned i=0;i!=1000;++i)//2
{
svec.push_back(i+"test");
}
svec.resize(svec.size()+svec.size()/2);//3
cout << "test>>" << svec.size() << endl; cout << "capacity>>" << svec.capacity() << endl;//4,此处输出2000,新分配的空间为原空间的三分之一[新分配空间依赖具体实现]. return 0; }

源码4

一直在重申[capacity]的值依赖具体实现,因此可能不同平台,输出结果不同.每个vector的实现策略不同(比如gcc,ms vc),但是必须遵守一个原则:只有当迫不得已时才会分配新内存空间.


/*************************************************************************
> File Name: test.9.39.cpp
> Author: puruidong
> Mail: 1@w1520.com
> Created Time: 2014年05月22日 星期四
************************************************************************/

#include
#include
using namespace std;

int main()
{
/*

解释下面的程序片段做了什么?
1.要求系统分配一个1024大小的空间;
2.向vector中添加1048个元素;
3.缩小元素空间,vector中的实际元素是1048个,由于除法是优先运算的,
因此3的运算结果大致是1048+1048/2=1572.
*****************************************************************
此处vector实际元素已经超出了预先分配的空间,因此必须新分配内存空间,新分配的空间长度不少于元素的个数.
而capacity的值也会发生变化,{这依赖具体实现}.capacity在此处输出:2048[在实际元素数量上增加了1000个内存空间].

*/
vector svec;
svec.reserve(1024);//1
//while(cin >> word)
for(unsigned i=0;i!=1048;++i)//2
{
svec.push_back(i+"test");
}
svec.resize(svec.size()+svec.size()/2);//3
cout << "test>>" << svec.size() << endl; cout << "capacity>>" << svec.capacity() << endl;//4 return 0; }

关于capacity还有很多问题值得思考,上面的程序在gcc 4.8.2上测试通过[使用C++11进行编译].

JavaScript:全国城市数组[升级版]

说明

部分资料来自网上,若自行调用,一定要注意城市数组里面的部分下标为空的元素。

下面是源文件,自己整合测试一下就可以了.

html

queryhotelcitylist.js

城市数组.


/****************
@author:pruidong
@date:2014.5.20
@web:07q.net
***************/

//初始化各个城

var citysFlight=new Array();

citysFlight[0]=new Array('pek','北京','beijing','bj');

citysFlight[1]=new Array('can','广州','guangzhou','gz');

citysFlight[2]=new Array('szx','深圳','shenzhen','sz');

citysFlight[3]=new Array('csx','长沙','changsha','cs');

citysFlight[4]=new Array('ctu','成都','chengdu','cd');

citysFlight[5]=new Array('ckg','重庆','chongqing','cq');

citysFlight[6]=new Array('foc','福州','fuzhou','fz');

citysFlight[7]=new Array('kwe','贵阳','guiyang','gy');

citysFlight[8]=new Array('hak','海口','haikou','hk');

citysFlight[9]=new Array('hgh','杭州','hangzhou','hz');

citysFlight[10]=new Array('kmg','昆明','kunming','km');

citysFlight[11]=new Array('khn','南昌','nanchang','nc');

citysFlight[12]=new Array('nkg','南京','nanjing','nj');

citysFlight[13]=new Array('syx','三亚','sanya','sy');

citysFlight[14]=new Array('sha','上海虹桥','shanghaihongqiao','shhq');

citysFlight[15]=new Array('pvg','上海浦东','shanghaipudong','shpd');

citysFlight[16]=new Array('she','沈阳','shenyang','sy');

citysFlight[17]=new Array('wnz','温州','wenzhou','wz');

citysFlight[18]=new Array('wuh','武汉','wuhan','wh');

citysFlight[19]=new Array('xmn','厦门','xiamen','xm');

citysFlight[20]=new Array('sia','西安','xian','xa');

citysFlight[21]=new Array('cgo','郑州','zhengzhou','zz');

citysFlight[22]=new Array('swa','汕头','sangtou','st');

citysFlight[23]=new Array('tyn','太原','taiyuan','ty');

citysFlight[24]=new Array('tsn','天津','tianjin','tj');

citysFlight[25]=new Array('urc','乌鲁木齐','wulumuqi','wlmq');

citysFlight[26]=new Array('yiw','义乌','yiwu','yw');

citysFlight[27]=new Array('zha','湛江','zhanjiang','zj');

citysFlight[28]=new Array('cgo','长春','changchun','cc');

citysFlight[29]=new Array('dlc','大连','dalian','dl');

citysFlight[30]=new Array('kwl','桂林','guilin','gl');

citysFlight[31]=new Array('hrb','哈尔滨','haerbin','heb');

citysFlight[32]=new Array('hfe','合肥','hefei','hf');

citysFlight[33]=new Array('tna','济南','jinan','jn');

citysFlight[34]=new Array('nng','南宁','nanning','nn');

citysFlight[35]=new Array('ngb','宁波','ningbo','nb');

citysFlight[36]=new Array('tao','青岛','qingdao','qd');

citysFlight[37]=new Array('jmu','佳木斯','jiamusi','jms');

citysFlight[38]=new Array('mdg','牡丹江','mudanjiang','mdj');

citysFlight[39]=new Array('ynj','延吉','yanji','yj');

citysFlight[40]=new Array('het','呼和浩特','huhehaote','hhht');

//国际始发

citysFlight[41]=new Array('icn','首尔','shouer','se');

citysFlight[42]=new Array('cju','济州','jizhou','jz');

citysFlight[43]=new Array('pus','釜山','fushan','fs');

citysFlight[44]=new Array('tae','大邱','daqiu','dq');

citysFlight[45]=new Array('del','新德里','xindeli','xdl');

citysFlight[46]=new Array('kix','大阪','daban','db');

citysFlight[47]=new Array('ngo','名古屋','mingguwu','mgw');

citysFlight[48]=new Array('nrt','东京','dongjing','dj');

citysFlight[49]=new Array('fuk','福冈','fugang','fg');

citysFlight[50]=new Array('HKG','香港','xianggang','xg');

citysFlight[51]=new Array('TPE','台北','taibei','tb');

citysFlight[52]=new Array('SIN','新加坡','xinjiapo','xjp');

citysFlight[53]=new Array('BKK','曼谷','mangu','mg');

citysFlight[54]=new Array('JKT','雅加达','yajiada','yjd');

citysFlight[55]=new Array('KUL','吉隆坡','jilongpo','jlp');

citysFlight[56]=new Array('REP','暹粒','xianli','xl');

citysFlight[57]=new Array('PNH','金边','jinbian','jb');

citysFlight[58]=new Array('KTM','加德满都','jiademandu','jdmd');

citysFlight[59]=new Array('SGN','胡志明','huzhiming','hzm');

citysFlight[60]=new Array('HAN','河内','henei','hl');

citysFlight[61]=new Array('MNL','马尼拉','manila','man');

citysFlight[62]=new Array('RGN','仰光','yanguang','yg');

citysFlight[63]=new Array('PEN','槟城','bincheng','bc');

citysFlight[64]=new Array('MLE','马累','male','ml');

citysFlight[65]=new Array('DEL','新德里','xindeli','xdl');

citysFlight[66]=new Array('NRT','东京','dongjing','dj');

citysFlight[67]=new Array('KIJ','新泻','xinxie','xx');

citysFlight[68]=new Array('TOY','富山','fushan','fs');

citysFlight[69]=new Array('HIJ','广岛','guangdao','gd');

citysFlight[70]=new Array('SDJ','仙台','xiantai','xt');

citysFlight[71]=new Array('CTS','札幌','zhahuang','zh');

citysFlight[72]=new Array('HKG','迪拜','dibai','db');

citysFlight[73]=new Array('ALA','阿拉木图','alamitu','almt');

citysFlight[74]=new Array('IKA','德黑兰','deheilan','dhl');

citysFlight[75]=new Array('ISB','伊斯兰堡','yisilanbao','yslb');

citysFlight[76]=new Array('FRU','比什凯克','bierkaike','bekk');

citysFlight[77]=new Array('ASB','阿什哈巴德','ashenhabade','ashbd');

citysFlight[78]=new Array('BAK','巴库','baku','bk');

citysFlight[79]=new Array('VVO','海参崴','haishenwai','hsw');

citysFlight[80]=new Array('OVB','新西伯利亚','xinxiboliya','xxbly');

citysFlight[81]=new Array('DYU','杜尚别','dushangbie','dsb');

citysFlight[82]=new Array('OSS','奥什','aoshen','as');

citysFlight[83]=new Array('TAS','塔什干','tashengan','tsg');

citysFlight[84]=new Array('JED','吉达','jida','jd');

citysFlight[85]=new Array('DAC','达卡','daka','dk');

citysFlight[86]=new Array('SYD','悉尼','xini','xn');

citysFlight[87]=new Array('BNE','布里斯班','bulisiban','blsb');

citysFlight[88]=new Array('AKL','奥克兰','aokelan','akl');

citysFlight[89]=new Array('CDG','巴黎','bali','bl');

citysFlight[90]=new Array('AMS','阿姆斯特丹','amusitedan','amstd');

citysFlight[91]=new Array('LAX','洛杉矶','luoshanji','lsj');

citysFlight[92]=new Array('SVO','莫斯科','mosike','msk');

citysFlight[93]=new Array('YVR','温哥华','wengehua','wgh');

//国内新增数据
/*********************************

若自行调用时,一定要注意下面的空数组!!

***********************************/

citysFlight[94]=new Array("aldq","阿里地区","alidiqu","aldq");

citysFlight[95]=new Array("ales","阿拉尔","alaershi","ales");

citysFlight[96]=new Array("ays","安阳","anyangshi","ays");

citysFlight[97]=new Array("altdq","阿勒泰地区","aletaidiqu","altdq");

citysFlight[98]=new Array("aksdq","阿克苏地区","akesudiqu","aksdq");

citysFlight[99]=new Array("aqs","安庆","anqingshi","aqs");

citysFlight[100]=new Array("amtbxzq","澳门特别行政区","aomentebiexingzhengqu","amtbxzq");

citysFlight[101]=new Array("aks","安康","ankangshi","aks");

citysFlight[102]=new Array("ass","安顺","anshunshi","ass");

citysFlight[103]=new Array("ass","鞍山","anshanshi","ass");

citysFlight[104]=new Array("alsm","阿拉善盟","alashanmeng","alsm");

citysFlight[105]=new Array("abzzqzzzz","阿坝","abazangzuqiangzuzizhizhou","abzzqzzzz");

citysFlight[106]=new Array("","","","");

citysFlight[107]=new Array("","","","");

citysFlight[108]=new Array("bss","百色","baiseshi","bss");

citysFlight[109]=new Array("bzs","巴中","bazhongshi","bzs");

citysFlight[110]=new Array("bhs","北海","beihaishi","bhs");

citysFlight[111]=new Array("bjdq","毕节地区","bijiediqu","bjdq");

citysFlight[112]=new Array("bds","保定","baodingshi","bds");

citysFlight[113]=new Array("bzs","亳州","bozhoushi","bzs");

citysFlight[114]=new Array("bzs","滨州","binzhoushi","bzs");

citysFlight[115]=new Array("bxs","本溪","benxishi","bxs");

citysFlight[116]=new Array("bjs","宝鸡","baojishi","bjs");

citysFlight[117]=new Array("bynes","巴彦淖尔","bayannaoershi","bynes");

citysFlight[118]=new Array("byglmgzzz","巴音","bayinguolengmengguzizhizhou","byglmgzzz");

citysFlight[119]=new Array("bts","包头","baotoushi","bts");

citysFlight[120]=new Array("bbs","蚌埠","bengbushi","bbs");

citysFlight[121]=new Array("bss","白山","baishanshi","bss");

citysFlight[122]=new Array("bjs","北京","beijingshi","bjs");

citysFlight[123]=new Array("bss","保山","baoshanshi","bss");

citysFlight[124]=new Array("bcs","白城","baichengshi","bcs");

citysFlight[125]=new Array("bys","白银","baiyinshi","bys");

citysFlight[126]=new Array("betlmgzzz","博尔塔拉","boertalamengguzizhizhou","betlmgzzz");

citysFlight[127]=new Array("","","","");

citysFlight[128]=new Array("","","","");

citysFlight[129]=new Array("chs","巢湖","chaohushi","chs");

citysFlight[130]=new Array("cqs","重庆","chongqingshi","cqs");

citysFlight[131]=new Array("czs","沧州","cangzhoushi","czs");

citysFlight[132]=new Array("czs","潮州","chaozhoushi","czs");

citysFlight[133]=new Array("czs","郴州","chenzhoushi","czs");

citysFlight[134]=new Array("zys","朝阳","zhaoyangshi","zys");

citysFlight[135]=new Array("cds","承德","chengdeshi","cds");

citysFlight[136]=new Array("czs","滁州","chuzhoushi","czs");

citysFlight[137]=new Array("czs","常州","changzhoushi","czs");

citysFlight[138]=new Array("cds","常德","changdeshi","cds");

citysFlight[139]=new Array("cddq","昌都地区","changdoudiqu","cddq");

citysFlight[140]=new Array("czs","池州","chizhoushi","czs");

citysFlight[141]=new Array("cxyzzzz","楚雄","chuxiongyizuzizhizhou","cxyzzzz");

citysFlight[142]=new Array("cjhzzzz","昌吉","changjihuizuzizhizhou","cjhzzzz");

citysFlight[143]=new Array("cds","成都","chengdushi","cds");

citysFlight[144]=new Array("czs","崇左","chongzuoshi","czs");

citysFlight[145]=new Array("cfs","赤峰","chifengshi","cfs");

citysFlight[146]=new Array("","","","");

citysFlight[147]=new Array("","","","");

citysFlight[148]=new Array("dgs","东莞","dongguanshi","dgs");

citysFlight[149]=new Array("dds","丹东","dandongshi","dds");

citysFlight[150]=new Array("dxs","定西","dingxishi","dxs");

citysFlight[151]=new Array("dlbzzzz","大理","dalibaizuzizhizhou","dlbzzzz");

citysFlight[152]=new Array("dxaldq","大兴安岭地区","daxinganlingdiqu","dxaldq");

citysFlight[153]=new Array("dqzzzzz","迪庆藏族自治州","diqingzangzuzizhizhou","dqzzzzz");

citysFlight[154]=new Array("dzs","达州","dazhoushi","dzs");

citysFlight[155]=new Array("dys","德阳","deyangshi","dys");

citysFlight[156]=new Array("dzs","德州","dezhoushi","dzs");

citysFlight[157]=new Array("dhdzjpzzzz","德宏傣族景","dehongdaizujingpozuzizhizhou","dhdzjpzzzz");

citysFlight[158]=new Array("dys","东营","dongyingshi","dys");

citysFlight[159]=new Array("dqs","大庆","daqingshi","dqs");

citysFlight[160]=new Array("dts","大同","datongshi","dts");

citysFlight[161]=new Array("dls","大连","dalianshi","dls");

citysFlight[162]=new Array("","","","");

citysFlight[163]=new Array("","","","");

citysFlight[164]=new Array("estjzmzzzz","恩施","enshitujiazumiaozuzizhizhou","estjzmzzzz");

citysFlight[165]=new Array("eedss","鄂尔多斯","eerduosishi","eedss");

citysFlight[166]=new Array("ezs","鄂州","ezhoushi","ezs");

citysFlight[167]=new Array("","","","");

citysFlight[168]=new Array("","","","");

citysFlight[169]=new Array("fzs","福州","fuzhoushi","fzs");

citysFlight[170]=new Array("fxs","阜新","fuxinshi","fxs");

citysFlight[171]=new Array("fss","抚顺","fushunshi","fss");

citysFlight[172]=new Array("fys","阜阳","fuyangshi","fys");

citysFlight[173]=new Array("fzs","抚州","fuzhoushi","fzs");

citysFlight[174]=new Array("fcgs","防城港","fangchenggangshi","fcgs");

citysFlight[175]=new Array("fss","佛山","foshanshi","fss");

citysFlight[176]=new Array("","","","");

citysFlight[177]=new Array("","","","");

citysFlight[178]=new Array("gzs","赣州","ganzhoushi","gzs");

citysFlight[179]=new Array("gzs","广州","guangzhoushi","gzs");

citysFlight[180]=new Array("gys","贵阳","guiyangshi","gys");

citysFlight[181]=new Array("glzzzzz","果洛","guoluozangzuzizhizhou","glzzzzz");

citysFlight[182]=new Array("gys","固原","guyuanshi","gys");

citysFlight[183]=new Array("gls","桂林","guilinshi","gls");

citysFlight[184]=new Array("gas","广安","guanganshi","gas");

citysFlight[185]=new Array("gzzzzzz","甘孜","ganzizangzuzizhizhou","gzzzzzz");

citysFlight[186]=new Array("gys","广元","guangyuanshi","gys");

citysFlight[187]=new Array("ggs","贵港","guigangshi","ggs");

citysFlight[188]=new Array("gnzzzzz","甘南","gannanzangzuzizhizhou","gnzzzzz");

citysFlight[189]=new Array("","","","");

citysFlight[190]=new Array("","","","");

citysFlight[191]=new Array("hhs","怀化","huaihuashi","hhs");

citysFlight[192]=new Array("hfs","合肥","hefeishi","hfs");

citysFlight[193]=new Array("hgs","黄冈","huanggangshi","hgs");

citysFlight[194]=new Array("hlds","葫芦岛","huludaoshi","hlds");

citysFlight[195]=new Array("hmdq","哈密地区","hamidiqu","hmdq");

citysFlight[196]=new Array("hhhts","呼和浩特","huhehaoteshi","hhhts");

citysFlight[197]=new Array("has","淮安","huaianshi","has");

citysFlight[198]=new Array("hbs","鹤壁","hebishi","hbs");

citysFlight[199]=new Array("hzs","贺州","hezhoushi","hzs");

citysFlight[200]=new Array("hzs","荷泽","hezeshi","hzs");

citysFlight[201]=new Array("hebs","哈尔滨","haerbinshi","hebs");

citysFlight[202]=new Array("hbzzzzz","海北","haibeizangzuzizhizhou","hbzzzzz");

citysFlight[203]=new Array("hnzzzzz","海南","hainanzangzuzizhizhou","hnzzzzz");

citysFlight[204]=new Array("hzs","杭州","hangzhoushi","hzs");

citysFlight[205]=new Array("hnzzzzz","黄南","huangnanzangzuzizhizhou","hnzzzzz");

citysFlight[206]=new Array("htdq","和田地区","hetiandiqu","htdq");

citysFlight[207]=new Array("hxmgzzzzzz","海西","haiximengguzuzangzuzizhizhou","hxmgzzzzzz");

citysFlight[208]=new Array("hds","邯郸","handanshi","hds");

citysFlight[209]=new Array("hhhnzyzzzz","红河","honghehanizuyizuzizhizhou","hhhnzyzzzz");

citysFlight[210]=new Array("hcs","河池","hechishi","hcs");

citysFlight[211]=new Array("hgs","鹤岗","hegangshi","hgs");

citysFlight[212]=new Array("hss","衡水","hengshuishi","hss");

citysFlight[213]=new Array("hddq","海东地区","haidongdiqu","hddq");

citysFlight[214]=new Array("hks","海口","haikoushi","hks");

citysFlight[215]=new Array("hzs","湖州","huzhoushi","hzs");

citysFlight[216]=new Array("hss","黄山","huangshanshi","hss");

citysFlight[217]=new Array("hbs","淮北","huaibeishi","hbs");

citysFlight[218]=new Array("hlbes","呼伦贝尔","hulunbeiershi","hlbes");

citysFlight[219]=new Array("hys","衡阳","hengyangshi","hys");

citysFlight[220]=new Array("hns","淮南","huainanshi","hns");

citysFlight[221]=new Array("hhs","黑河","heiheshi","hhs");

citysFlight[222]=new Array("hzs","汉中","hanzhongshi","hzs");

citysFlight[223]=new Array("hys","河源","heyuanshi","hys");

citysFlight[224]=new Array("hzs","惠州","huizhoushi","hzs");

citysFlight[225]=new Array("hss","黄石","huangshishi","hss");

citysFlight[226]=new Array("","","","");

citysFlight[227]=new Array("","","","");

citysFlight[228]=new Array("jzs","锦州","jinzhoushi","jzs");

citysFlight[229]=new Array("jns","济南","jinanshi","jns");

citysFlight[230]=new Array("jns","济宁","jiningshi","jns");

citysFlight[231]=new Array("jjs","九江","jiujiangshi","jjs");

citysFlight[232]=new Array("jhs","金华","jinhuashi","jhs");

citysFlight[233]=new Array("jcs","金昌","jinchangshi","jcs");

citysFlight[234]=new Array("jxs","鸡西","jixishi","jxs");

citysFlight[235]=new Array("jms","江门","jiangmenshi","jms");

citysFlight[236]=new Array("jygs","嘉峪关","jiayuguanshi","jygs");

citysFlight[237]=new Array("jcs","晋城","jinchengshi","jcs");

citysFlight[238]=new Array("jxs","嘉兴","jiaxingshi","jxs");

citysFlight[239]=new Array("jdzs","景德镇","jingdezhenshi","jdzs");

citysFlight[240]=new Array("jmss","佳木斯","jiamusishi","jmss");

citysFlight[241]=new Array("jas","吉安","jianshi","jas");

citysFlight[242]=new Array("jzs","焦作","jiaozuoshi","jzs");

citysFlight[243]=new Array("jms","荆门","jingmenshi","jms");

citysFlight[244]=new Array("jys","揭阳","jieyangshi","jys");

citysFlight[245]=new Array("jls","吉林","jilinshi","jls");

citysFlight[246]=new Array("jqs","酒泉","jiuquanshi","jqs");

citysFlight[247]=new Array("jzs","晋中","jinzhongshi","jzs");

citysFlight[248]=new Array("jzs","荆州","jingzhoushi","jzs");

citysFlight[249]=new Array("","","","");

citysFlight[250]=new Array("","","","");

citysFlight[251]=new Array("kfs","开封","kaifengshi","kfs");

citysFlight[252]=new Array("klmys","克拉玛依","kelamayishi","klmys");

citysFlight[253]=new Array("kms","昆明","kunmingshi","kms");

citysFlight[254]=new Array("kzlskekzzzz","克孜勒苏柯尔克孜","kezilesukeerkezizizhizhou","kzlskekzzzz");

citysFlight[255]=new Array("ksdq","喀什地区","kashidiqu","ksdq");

citysFlight[256]=new Array("","","","");

citysFlight[257]=new Array("","","","");

citysFlight[258]=new Array("lss","拉萨","lasashi","lss");

citysFlight[259]=new Array("lygs","连云港","lianyungangshi","lygs");

citysFlight[260]=new Array("ljs","丽江","lijiangshi","ljs");

citysFlight[261]=new Array("lhs","漯河","luoheshi","lhs");

citysFlight[262]=new Array("lzs","兰州","lanzhoushi","lzs");

citysFlight[263]=new Array("las","六安","liuanshi","las");

citysFlight[264]=new Array("lzdq","林芝地区","linzhidiqu","lzdq");

citysFlight[265]=new Array("lys","辽源","liaoyuanshi","lys");

citysFlight[266]=new Array("lds","娄底","loudishi","lds");

citysFlight[267]=new Array("lfs","廊坊","langfangshi","lfs");

citysFlight[268]=new Array("lss","丽水","lishuishi","lss");

citysFlight[269]=new Array("lys","辽阳","liaoyangshi","lys");

citysFlight[270]=new Array("lys","临沂","linyishi","lys");

citysFlight[271]=new Array("lzs","柳州","liuzhoushi","lzs");

citysFlight[272]=new Array("lpss","六盘水","liupanshuishi","lpss");

citysFlight[273]=new Array("lys","洛阳","luoyangshi","lys");

citysFlight[274]=new Array("lns","陇南","longnanshi","lns");

citysFlight[275]=new Array("lsyzzzz","凉山","liangshanyizuzizhizhou","lsyzzzz");

citysFlight[276]=new Array("lcs","临沧","lincangshi","lcs");

citysFlight[277]=new Array("lxhzzzz","临夏","linxiahuizuzizhizhou","lxhzzzz");

citysFlight[278]=new Array("lcs","聊城","liaochengshi","lcs");

citysFlight[279]=new Array("lys","龙岩","longyanshi","lys");

citysFlight[280]=new Array("lfs","临汾","linfenshi","lfs");

citysFlight[281]=new Array("lls","吕梁","lvliangshi","lls");

citysFlight[282]=new Array("lzs","泸州","luzhoushi","lzs");

citysFlight[283]=new Array("lws","莱芜","laiwushi","lws");

citysFlight[284]=new Array("lss","乐山","leshanshi","lss");

citysFlight[285]=new Array("lbs","来宾","laibinshi","lbs");

citysFlight[286]=new Array("","","","");

citysFlight[287]=new Array("","","","");

citysFlight[288]=new Array("mass","马鞍山","maanshanshi","mass");

citysFlight[289]=new Array("mms","茂名","maomingshi","mms");

citysFlight[290]=new Array("mys","绵阳","mianyangshi","mys");

citysFlight[291]=new Array("mss","眉山","meishanshi","mss");

citysFlight[292]=new Array("mzs","梅州","meizhoushi","mzs");

citysFlight[293]=new Array("mdjs","牡丹江","mudanjiangshi","mdjs");

citysFlight[294]=new Array("","","","");

citysFlight[295]=new Array("","","","");

citysFlight[296]=new Array("nps","南平","nanpingshi","nps");

citysFlight[297]=new Array("nds","宁德","ningdeshi","nds");

citysFlight[298]=new Array("ncs","南昌","nanchangshi","ncs");

citysFlight[299]=new Array("nts","南通","nantongshi","nts");

citysFlight[300]=new Array("njs","南京","nanjingshi","njs");

citysFlight[301]=new Array("nys","南阳","nanyangshi","nys");

citysFlight[302]=new Array("nns","南宁","nanningshi","nns");

citysFlight[303]=new Array("njlszzzz","怒江","nujianglisuzuzizhizhou","njlszzzz");

citysFlight[304]=new Array("njs","内江","neijiangshi","njs");

citysFlight[305]=new Array("nbs","宁波","ningboshi","nbs");

citysFlight[306]=new Array("nqdq","那曲地区","naqudiqu","nqdq");

citysFlight[307]=new Array("ncs","南充","nanchongshi","ncs");

citysFlight[308]=new Array("","","","");

citysFlight[309]=new Array("","","","");

citysFlight[310]=new Array("pxs","萍乡","pingxiangshi","pxs");

citysFlight[311]=new Array("pls","平凉","pingliangshi","pls");

citysFlight[312]=new Array("pzhs","攀枝花","panzhihuashi","pzhs");

citysFlight[313]=new Array("pys","濮阳","puyangshi","pys");

citysFlight[314]=new Array("pjs","盘锦","panjinshi","pjs");

citysFlight[315]=new Array("pts","莆田","putianshi","pts");

citysFlight[316]=new Array("pdss","平顶山","pingdingshanshi","pdss");

citysFlight[317]=new Array("","","","");

citysFlight[318]=new Array("","","","");

citysFlight[319]=new Array("qzs","钦州","qinzhoushi","qzs");

citysFlight[320]=new Array("qzs","衢州","quzhoushi","qzs");

citysFlight[321]=new Array("qys","清远","qingyuanshi","qys");

citysFlight[322]=new Array("qqhes","齐齐哈尔","qiqihaershi","qqhes");

citysFlight[323]=new Array("qnbyzmzzzz","黔南","qiannanbuyizumiaozuzizhizhou","qnbyzmzzzz");

citysFlight[324]=new Array("qths","七台河","qitaiheshi","qths");

citysFlight[325]=new Array("qds","青岛","qingdaoshi","qds");

citysFlight[326]=new Array("qdnmzdzzzz","黔东南","qiandongnanmiaozudongzuzizhizhou","qdnmzdzzzz");

citysFlight[327]=new Array("qhds","秦皇岛","qinhuangdaoshi","qhds");

citysFlight[328]=new Array("qys","庆阳","qingyangshi","qys");

citysFlight[329]=new Array("qxnbyzmzzzz","黔西南","qianxinanbuyizumiaozuzizhizhou","qxnbyzmzzzz");

citysFlight[330]=new Array("qjs","曲靖","qujingshi","qjs");

citysFlight[331]=new Array("qzs","泉州","quanzhoushi","qzs");

citysFlight[332]=new Array("","","","");

citysFlight[333]=new Array("","","","");

citysFlight[334]=new Array("rzs","日照","rizhaoshi","rzs");

citysFlight[335]=new Array("rkzdq","日喀则地区","rikazediqu","rkzdq");

citysFlight[336]=new Array("","","","");

citysFlight[337]=new Array("","","","");

citysFlight[338]=new Array("sgs","韶关","shaoguanshi","sgs");

citysFlight[339]=new Array("shzs","石河子","shihezishi","shzs");

citysFlight[340]=new Array("sndq","山南地区","shannandiqu","sndq");

citysFlight[341]=new Array("szss","石嘴山","shizuishanshi","szss");

citysFlight[342]=new Array("syss","双鸭山","shuangyashanshi","syss");

citysFlight[343]=new Array("szs","深圳","shenzhenshi","szs");

citysFlight[344]=new Array("sms","三明","sanmingshi","sms");

citysFlight[345]=new Array("shs","上海","shanghaishi","shs");

citysFlight[346]=new Array("sxs","绍兴","shaoxingshi","sxs");

citysFlight[347]=new Array("shs","绥化","suihuashi","shs");

citysFlight[348]=new Array("szs","苏州","suzhoushi","szs");

citysFlight[349]=new Array("szs","宿州","suzhoushi","szs");

citysFlight[350]=new Array("snj","神农架","shennongjia","snj");

citysFlight[351]=new Array("sys","邵阳","shaoyangshi","sys");

citysFlight[352]=new Array("sys","十堰","shiyanshi","sys");

citysFlight[353]=new Array("sws","汕尾","shanweishi","sws");

citysFlight[354]=new Array("srs","上饶","shangraoshi","srs");

citysFlight[355]=new Array("sps","四平","sipingshi","sps");

citysFlight[356]=new Array("sjzs","石家庄","shijiazhuangshi","sjzs");

citysFlight[357]=new Array("szs","随州","suizhoushi","szs");

citysFlight[358]=new Array("smxs","三门峡","sanmenxiashi","smxs");

citysFlight[359]=new Array("sts","汕头","shantoushi","sts");

citysFlight[360]=new Array("sns","遂宁","suiningshi","sns");

citysFlight[361]=new Array("sqs","商丘","shangqiushi","sqs");

citysFlight[362]=new Array("szs","朔州","shuozhoushi","szs");

citysFlight[363]=new Array("sms","思茅","simaoshi","sms");

citysFlight[364]=new Array("sys","沈阳","shenyangshi","sys");

citysFlight[365]=new Array("sls","商洛","shangluoshi","sls");

citysFlight[366]=new Array("sys","三亚","sanyashi","sys");

citysFlight[367]=new Array("sqs","宿迁","suqianshi","sqs");

citysFlight[368]=new Array("sys","松原","songyuanshi","sys");

citysFlight[369]=new Array("xms","厦门","xiamenshi","xms");

citysFlight[370]=new Array("","","","");

citysFlight[371]=new Array("","","","");

citysFlight[372]=new Array("tys","太原","taiyuanshi","tys");

citysFlight[373]=new Array("tmsks","图木舒克","tumushukeshi","tmsks");

citysFlight[374]=new Array("tls","通辽","tongliaoshi","tls");

citysFlight[375]=new Array("tcdq","塔城地区","tachengdiqu","tcdq");

citysFlight[376]=new Array("tlfdq","吐鲁番地区","tulufandiqu","tlfdq");

citysFlight[377]=new Array("tzs","泰州","taizhoushi","tzs");

citysFlight[378]=new Array("ths","通化","tonghuashi","ths");

citysFlight[379]=new Array("tzs","台州","taizhoushi","tzs");

citysFlight[380]=new Array("tls","铜陵","tonglingshi","tls");

citysFlight[381]=new Array("tjs","天津","tianjinshi","tjs");

citysFlight[382]=new Array("tls","铁岭","tielingshi","tls");

citysFlight[383]=new Array("tcs","铜川","tongchuanshi","tcs");

citysFlight[384]=new Array("tas","泰安","taianshi","tas");

citysFlight[385]=new Array("tss","唐山","tangshanshi","tss");

citysFlight[386]=new Array("trdq","铜仁地区","tongrendiqu","trdq");

citysFlight[387]=new Array("tss","天水","tianshuishi","tss");

citysFlight[388]=new Array("tws","台湾省","taiwansheng","tws");

citysFlight[389]=new Array("","","","");

citysFlight[390]=new Array("","","","");

citysFlight[391]=new Array("wzs","温州","wenzhoushi","wzs");

citysFlight[392]=new Array("whs","武汉","wuhanshi","whs");

citysFlight[393]=new Array("wws","武威","wuweishi","wws");

citysFlight[394]=new Array("wlmqs","乌鲁木齐","wulumuqishi","wlmqs");

citysFlight[395]=new Array("wjqs","五家渠","wujiaqushi","wjqs");

citysFlight[396]=new Array("whs","威海","weihaishi","whs");

citysFlight[397]=new Array("whs","芜湖","wuhushi","whs");

citysFlight[398]=new Array("wzs","梧州","wuzhoushi","wzs");

citysFlight[399]=new Array("wxs","无锡","wuxishi","wxs");

citysFlight[400]=new Array("whs","乌海","wuhaishi","whs");

citysFlight[401]=new Array("wfs","潍坊","weifangshi","wfs");

citysFlight[402]=new Array("wzs","吴忠","wuzhongshi","wzs");

citysFlight[403]=new Array("wlcbs","乌兰察布","wulanchabushi","wlcbs");

citysFlight[404]=new Array("wns","渭南","weinanshi","wns");

citysFlight[405]=new Array("wszzmzzzz","文山","wenshanzhuangzumiaozuzizhizhou","wszzmzzzz");

citysFlight[406]=new Array("","","","");

citysFlight[407]=new Array("","","","");

citysFlight[408]=new Array("xts","湘潭","xiangtanshi","xts");

citysFlight[409]=new Array("xlglm","锡林郭勒盟","xilinguolemeng","xlglm");

citysFlight[410]=new Array("xzs","徐州","xuzhoushi","xzs");

citysFlight[411]=new Array("xzs","忻州","xinzhoushi","xzs");

citysFlight[412]=new Array("xfs","襄樊","xiangfanshi","xfs");

citysFlight[413]=new Array("xys","信阳","xinyangshi","xys");

citysFlight[414]=new Array("xas","西安","xianshi","xas");

citysFlight[415]=new Array("xxs","新乡","xinxiangshi","xxs");

citysFlight[416]=new Array("xxtjzmzzzz","湘西","xiangxitujiazumiaozuzizhizhou","xxtjzmzzzz");

citysFlight[417]=new Array("xts","邢台","xingtaishi","xts");

citysFlight[418]=new Array("xys","新余","xinyushi","xys");

citysFlight[419]=new Array("xam","兴安盟","xinganmeng","xam");

citysFlight[420]=new Array("xcs","许昌","xuchangshi","xcs");

citysFlight[421]=new Array("xcs","宣城","xuanchengshi","xcs");

citysFlight[422]=new Array("xgs","孝感","xiaoganshi","xgs");

citysFlight[423]=new Array("xns","西宁","xiningshi","xns");

citysFlight[424]=new Array("xys","咸阳","xianyangshi","xys");

citysFlight[425]=new Array("xns","咸宁","xianningshi","xns");

citysFlight[426]=new Array("xgtbxzq","香港特别行政区","xianggangtebiexingzhengqu","xgtbxzq");

citysFlight[427]=new Array("xsbndzzzz","西双版纳","xishuangbannadaizuzizhizhou","xsbndzzzz");

citysFlight[428]=new Array("","","","");

citysFlight[429]=new Array("","","","");

citysFlight[430]=new Array("ycs","宜昌","yichangshi","ycs");

citysFlight[431]=new Array("ycs","伊春","yichunshi","ycs");

citysFlight[432]=new Array("yas","雅安","yaanshi","yas");

citysFlight[433]=new Array("ycs","宜春","yichunshi","ycs");

citysFlight[434]=new Array("yszzzzz","玉树藏族自治州","yushuzangzuzizhizhou","yszzzzz");

citysFlight[435]=new Array("ycs","盐城","yanchengshi","ycs");

citysFlight[436]=new Array("yts","烟台","yantaishi","yts");

citysFlight[437]=new Array("yts","鹰潭","yingtanshi","yts");

citysFlight[438]=new Array("yzs","扬州","yangzhoushi","yzs");

citysFlight[439]=new Array("yks","营口","yingkoushi","yks");

citysFlight[440]=new Array("ycs","银川","yinchuanshi","ycs");

citysFlight[441]=new Array("ycs","运城","yunchengshi","ycs");

citysFlight[442]=new Array("yys","益阳","yiyangshi","yys");

citysFlight[443]=new Array("yls","玉林","yulinshi","yls");

citysFlight[444]=new Array("yqs","阳泉","yangquanshi","yqs");

citysFlight[445]=new Array("yjs","阳江","yangjiangshi","yjs");

citysFlight[446]=new Array("ybcxzzzz","延边","yanbianchaoxianzuzizhizhou","ybcxzzzz");

citysFlight[447]=new Array("yxs","玉溪","yuxishi","yxs");

citysFlight[448]=new Array("ybs","宜宾","yibinshi","ybs");

citysFlight[449]=new Array("yfs","云浮","yunfushi","yfs");

citysFlight[450]=new Array("yzs","永州","yongzhoushi","yzs");

citysFlight[451]=new Array("yys","岳阳","yueyangshi","yys");

citysFlight[452]=new Array("yls","榆林","yulinshi","yls");

citysFlight[453]=new Array("yas","延安","yananshi","yas");

citysFlight[454]=new Array("ylhskzzz","伊犁","yilihasakezizhizhou","ylhskzzz");

citysFlight[455]=new Array("","","","");

citysFlight[456]=new Array("","","","");

citysFlight[457]=new Array("zjjs","张家界","zhangjiajieshi","zjjs");

citysFlight[458]=new Array("czs","长治","changzhishi","czs");

citysFlight[459]=new Array("zjs","湛江","zhanjiangshi","zjs");

citysFlight[460]=new Array("zss","中山","zhongshanshi","zss");

citysFlight[461]=new Array("zmds","驻马店","zhumadianshi","zmds");

citysFlight[462]=new Array("zqs","肇庆","zhaoqingshi","zqs");

citysFlight[463]=new Array("ccs","长春","changchunshi","ccs");

citysFlight[464]=new Array("zbs","淄博","ziboshi","zbs");

citysFlight[465]=new Array("zss","舟山","zhoushanshi","zss");

citysFlight[466]=new Array("zgs","自贡","zigongshi","zgs");

citysFlight[467]=new Array("zys","资阳","ziyangshi","zys");

citysFlight[468]=new Array("zhs","珠海","zhuhaishi","zhs");

citysFlight[469]=new Array("zks","周口","zhoukoushi","zks");

citysFlight[470]=new Array("zys","张掖","zhangyeshi","zys");

citysFlight[471]=new Array("zzs","郑州","zhengzhoushi","zzs");

citysFlight[472]=new Array("zys","遵义","zunyishi","zys");

citysFlight[473]=new Array("css","长沙","changshashi","css");

citysFlight[474]=new Array("zzs","株洲","zhuzhoushi","zzs");

citysFlight[475]=new Array("zzs","漳州","zhangzhoushi","zzs");

citysFlight[476]=new Array("zzs","枣庄","zaozhuangshi","zzs");

citysFlight[477]=new Array("zts","昭通","zhaotongshi","zts");

citysFlight[478]=new Array("zws","中卫","zhongweishi","zws");

citysFlight[479]=new Array("zjks","张家口","zhangjiakoushi","zjks");

citysFlight[480]=new Array("zjs","镇江","zhenjiangshi","zjs");

queryticketcity.js

城市操作js.

(function($){
//城市操作js.

$.querycity = function(input,options){

var input = $(".choosesetout");//触发城市选择框.可以是按钮.

var sousuo = $(".Sousuocity");//城市返回框.

input.attr('autocomplete','off');

/*

if($.trim(input.val())=='' || $.trim(input.val())==options.defaultText){

input.val(options.defaultText).css('color','#aaa');

}

*/

var t_pop_focus = false;

var t_suggest_focus = false;

var t_suggest_page_click = false;//display:none

$('body').append("

");

$('body').append("

");

var popMain = $("#pop_city_"+input.attr('id'))

var popContainer = popMain.find('.pop_city_container');

var labelMain = popMain.find('.list_label');

var suggestMain = $("#suggest_city_"+input.attr('id'));

popMain.bgIframe();

suggestMain.bgIframe();

popInit();

resetPosition();

$(window).resize(function(){

resetPosition();

});

input.focus(function(){

if(t_suggest_page_click){

t_suggest_page_click = false;

return true;

}

suggestMain.hide();

if($.trim($(this).val())==options.defaultText){

$(this).val('').css('color','#000');

}

popMain.show();

}).click(function(){

if(t_suggest_page_click){

t_suggest_page_click = false;

return;

}

suggestMain.hide();

popMain.show();

}).blur(function(){

if(t_pop_focus == false){

popMain.hide();

if($.trim(input.val())=='' || $.trim(input.val())==options.defaultText){

input.val(options.defaultText).css('color','#aaa');

}

}

});

labelMain.find('a').live('click',function(){

input.focus();//使焦点在输入框,避免blur事件无法触发

t_pop_focus = true;

var labelId = $(this).attr('id');

labelMain.find('li a').removeClass('current');

$(this).addClass('current');

popContainer.find('ul').hide();

$("#"+labelId+'_container').show();

});

popContainer.find('a').live('click',function(){

input.text($(this).html());//将城市加载到元素

sousuo.val($(this).html());//将城市加载到元素.

//alert($(this).html());//输出选择城市

/////////////////////////////

popMain.hide();

});

popMain.mouseover(function(){

t_pop_focus = true;

}).mouseout(function(){

t_pop_focus = false;

});

input.blur(function(){

if( t_suggest_focus == false ){

if($(this).val()==''){

$(this).val( suggestMain.find('.list_city_container a.selected').children('b').text());

}

suggestMain.hide();

}

}).keydown(function(event){

popMain.hide();

event = window.event || event;

var keyCode = event.keyCode || event.which || event.charCode;

if (keyCode == 37) {//左

prevPage();

} else if (keyCode == 39) {//右

nextPage();

}else if(keyCode == 38){//上

prevResult();

}else if(keyCode == 40){//下

nextResult();

}

}).keypress(function(event){

event = window.event || event;

var keyCode = event.keyCode || event.which || event.charCode;

if(13 == keyCode){

if(suggestMain.find('.list_city_container a.selected').length > 0){

input.val(suggestMain.find('.list_city_container a.selected').children('b').text());

suggestMain.hide();

}

}

}).keyup(function(event){

event = window.event || event;

var keyCode = event.keyCode || event.which || event.charCode;

if(keyCode != 13 && keyCode != 37 && keyCode != 39 && keyCode !=9 && keyCode !=38 && keyCode !=40 ){

//keyCode == 9是tab切换键

queryCity();

}

});

suggestMain.find('.list_city_container a').live('click',function(){

input.val($(this).children('b').text());

suggestMain.hide();

}).live('mouseover',function(){

t_suggest_focus = true;

}).live('mouseout',function(){

t_suggest_focus = false;

});

suggestMain.find('.page_break a').live('mouseover',function(){

t_suggest_focus = true;

}).live('mouseout',function(){

t_suggest_focus = false;

});

suggestMain.find('.page_break a').live('click',function(event){

t_suggest_page_click = true;

input.click();

if($(this).attr('inum') != null){

setAddPage($(this).attr('inum'));

}

});

function nextPage(){

var add_cur= suggestMain.find(".page_break a.current").next();

if (add_cur != null) {

if ($(add_cur).attr("inum") != null) {

setAddPage($(add_cur).attr("inum"));

}

}

}

function prevPage(){

var add_cur = suggestMain.find(".page_break a.current").prev();

if (add_cur != null) {

if ($(add_cur).attr("inum") != null) {

setAddPage($(add_cur).attr("inum"));

}

}

}

function nextResult(){

var t_index = suggestMain.find('.list_city_container a').index(suggestMain.find('.list_city_container a.selected')[0]);

suggestMain.find('.list_city_container').children().removeClass('selected');

t_index += 1;

var t_end = suggestMain.find('.list_city_container a').index( suggestMain.find('.list_city_container a:visible').filter(':last')[0]);

if(t_index > t_end ){

t_index = suggestMain.find('.list_city_container a').index(suggestMain.find('.list_city_container a:visible').eq(0));

}

suggestMain.find('.list_city_container a').eq(t_index).addClass('selected');

}

function prevResult(){

var t_index = suggestMain.find('.list_city_container a').index(suggestMain.find('.list_city_container a.selected')[0]);

suggestMain.find('.list_city_container').children().removeClass('selected');

t_index -= 1;

var t_start = suggestMain.find('.list_city_container a').index(suggestMain.find('.list_city_container a:visible').filter(':first')[0]);

if( t_index < t_start){ t_index = suggestMain.find('.list_city_container a').index(suggestMain.find('.list_city_container a:visible').filter(':last')[0]); } suggestMain.find('.list_city_container a').eq(t_index).addClass('selected'); } function loadCity(){ var cityList = suggestMain.find('.list_city_container'); cityList.empty(); if(options.hotList){ var hotList = options.hotList; }else{ var hotList = [0,1,2,3,4,5,6,7,8,9]; } for(var item in hotList){ if(item>options.suggestLength){

return;

}

var _data = options.data[hotList[item]];

cityList.append(""+_data[2]+""+_data[1]+"");

}

suggestMain.find('.list_city_head').html(options.suggestTitleText);

setAddPage(1);

suggestMain.show();

setTopSelect();

}

function queryCity(){

popMain.hide();

var value = input.val().toLowerCase();

if( value.length == 0){

loadCity();

return;

}

var city_container = suggestMain.find('.list_city_container');

var isHave = false;

var _tmp = new Array();

for(var item in options.data){

var _data = options.data[item];

if(typeof (_data) != 'undefined'){

if(_data[2].indexOf(value) >= 0 || _data[3].indexOf(value) >= 0 || _data[1].indexOf(value) >=0 || _data[0].indexOf(value) >=0 ){

isHave = true;

_tmp.push(_data);

}

}

}

;

if(isHave){

city_container.empty();

for(var item in _tmp){

var _data= _tmp[item];

city_container.append(""+_data[2]+""+ _data[1] +"");

}

suggestMain.find('.list_city_head').html(value+",按拼音排序");

setAddPage(1);

setTopSelect()

}else{

suggestMain.find('.list_city_head').html("对不起,找不到"+value+"");

}

suggestMain.show();

}

function setAddPage(pageIndex){

suggestMain.find('.list_city_container a').removeClass('selected');

suggestMain.find('.list_city_container').children().each(function(i){

var k = i+1;

if(k> options.suggestLength*(pageIndex-1) && k <= options.suggestLength*pageIndex){ $(this).css('display','block'); }else{ $(this).hide(); } }); setTopSelect(); setAddPageHtml(pageIndex); } function setAddPageHtml(pageIndex){ var cityPageBreak = suggestMain.find('.page_break'); cityPageBreak.empty(); if(suggestMain.find('.list_city_container').children().length > options.suggestLength){

var pageBreakSize = Math.ceil(suggestMain.find('.list_city_container').children().length/options.suggestLength);

if(pageBreakSize <= 1){ return; } var start = end = pageIndex; for(var index = 0 ,num = 1 ; index < options.pageLength && num < options.pageLength; index++){ if(start > 1){

start--;num++;

}

if(end 1){

cityPageBreak.append("<-");

}

for(var i=start;i<=end;i++){ if(i == pageIndex){ cityPageBreak.append(""+(i)+""+(i)+"->");

}

cityPageBreak.show();

}else{

cityPageBreak.hide();

}

return;

}

function setTopSelect(){

if(suggestMain.find('.list_city_container').children().length > 0 ){

suggestMain.find('.list_city_container').children(':visible').eq(0).addClass('selected');

}

}

function onSelect(){

if( typeof options.onSelect == 'function'){

alert(1);

}

}

function popInit(){

var index = 0;

popMain.find('.pop_head').html(options.popTitleText);

if(!options.tabs){

popContainer.append("

    ");

    labelMain.remove();

    for( var item in options.data){

    $("#label_"+input.attr('id')+"_container").append("

  • "+options.data[item][1]+"
  • ");

    }

    return;

    }

    for(var itemLabel in options.tabs){

    index++;

    if(index == 1){

    popContainer.append("

      ");

      labelMain.append("

    • "+itemLabel+"
    • ");

      }else{

      popContainer.append("

      ");

      labelMain.append("

    • "+itemLabel+"
    • ");

      }

      for(var item in options.tabs[itemLabel]){

      var cityCode = options.tabs[itemLabel][item];

      if(!options.data[cityCode]){

      break;

      }

      $("#label_"+input.attr('id')+index+"_container").append("

    • "+options.data[cityCode][1]+"
    • ");

      }

      }

      }

      function resetPosition(){

      popMain.css({'top':input.position().top+input.outerHeight()+203,'left':input.position().left+192});

      suggestMain.css({'top':input.position().top+input.outerHeight()+203,'left':input.position().left+192});

      }

      }

      $.fn.querycity = function(options){

      var defaults = {

      'data' : {},

      'tabs' : '',

      'hotList' : '',

      'defaultText' : '中文/拼音',

      'popTitleText' : '请选择城市或输入城市名称的拼音或英文×',

      'suggestTitleText' : '输入中文/拼音或↑↓选择',

      'suggestLength' : 10,

      'pageLength' : 0,

      'onSelect' : ''

      };

      var options = $.extend(defaults,options);

      this.each(function(){

      new $.querycity(this,options);

      });

      return this;

      };

      })(jQuery);

      (function($){

      $.fn.bgIframe = $.fn.bgiframe = function(s) {

      if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {

      s = $.extend({

      top : 'auto', // auto == .currentStyle.borderTopWidth

      left : 'auto', // auto == .currentStyle.borderLeftWidth

      width : 'auto', // auto == offsetWidth

      height : 'auto', // auto == offsetHeight

      opacity : true,

      src : 'javascript:false;'

      }, s || {});

      var prop = function(n){return n&&n.constructor==Number?n+'px':n;},

      html = '