jQuery:如何自动完成“城市,州"? [英] JQuery: How to AutoComplete "City, State"?

查看:56
本文介绍了jQuery:如何自动完成“城市,州"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:如何使用 JQuery自动完成插件为输入字段建议位置("City, State")?

Question: How can you use the JQuery Auto-Completion plugin to suggest a location ("City, State") for an input field?

意思是,有人想输入伊利诺伊州芝加哥" ...,所以他们开始输入"Chi",它会自动建议"Chicago, IL".

Meaning, someone wants to type in "Chicago, IL" ... so they begin typing "Chi" and it auto-suggestions "Chicago, IL".

我最大的障碍是找到可以查询的服务,以找出美国的所有城市+州名称.

我本质上是想做StackOverflow标签"输入表单的工作,但要完成城市,州"表单的自动填写.

I essentially want to do what the StackOverflow "Tags" input form works but form "City, State" auto completion.

推荐答案

有一个名为GeoNames的组,它提供可下载的数据库和免费的Web服务来获取此类数据.例如,搜索

There's a group called GeoNames that offers both downloadable databases and free webservices to obtain this type of data. For example, the search

http://ws.geonames.org/searchJSON?name_startsWith=Chic&country=US

将返回一堆包含IL,Chicago的JSON(JSON属性包括"name":"Chicago"和"adminCode1":"IL").

will return a bunch of JSON that includes Chicago, IL (JSON properties include, among others, "name":"Chicago" and "adminCode1":"IL").

碰巧的是,jQuery UI伙计们将此数据源用于自动完成演示. (感谢NickT的链接).

As it happens, the jQuery UI folks used this datasource for a demo of autocomplete. (Thanks NickT for the link).

这篇关于jQuery:如何自动完成“城市,州"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆