如何在表单上实现城市/州字段的自动完成?
我想在表单文本框中实现城市和州自动建议。我该怎么做?
Weather.com 在其首页上有一个很好的示例。
问题:
- 在哪里可以找到美国城市和州配对的完整列表?有没有一个开放的 API 可以实现这一点?
- 是否存在任何现有脚本/框架已经执行文本框的城市+州自动建议任务?
I want to implement City and State auto suggest in a form textbox. How do I do this?
Weather.com has a great example on this on their front page.
Questions:
- Where can I find a complete USA listing of city and state pairings? And is there an open API for this?
- Do any existing scripts/frameworks exists that already perform this auto-suggest task of city+state for textboxes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您正在寻找人口> 的世界城市的良好数据库1000,查看 geonames.org 数据库。他们有可用的 sql 转储。除此之外,您还可以从此数据库中获取国家、地区和纬度/经度。
一般来说,如果您刚开始接触,可能对您有帮助的搜索词是 GIS(地理信息系统)。
If you're looking for a nice database of world cities with population > 1000, check out the geonames.org database. They have a sql dump available. Among other things, you'll also get countries, regions, and latitude/longitude from this database.
In general, the search term that might be helpful to you if you're getting your feet wet is GIS (geographic information systems).
尝试 http://plugins.jquery.com/project/jq-autocomplete
http://en.wikipedia.org/wiki/List_of_United_States_cities_by_population 或者,这个怎么样? http://www.census.gov/popest/cities/SUB- EST2008-4.html
这是美国人口普查局的官方页面。您可以解析 CSV。
此外,如果您已经拥有数组中的信息,则不需要 AJAX...但您必须先填充它。
您可能也想看到这个
http://forums.asp.net/t/1373395.aspx< /a>
try http://plugins.jquery.com/project/jq-autocomplete
http://en.wikipedia.org/wiki/List_of_United_States_cities_by_population or, how about this one? http://www.census.gov/popest/cities/SUB-EST2008-4.html
this is the oficial page of U.S. Census Bureau. You can parse the CSV.
Besides, you don't neeed AJAX if you have already the info in an array... but you have to fill it first.
You might wanna see this too
http://forums.asp.net/t/1373395.aspx
我建议您查看 jQuery 的 Freebase Suggest 插件,而不是维护自己的数据库。请参阅这个类似的问题。
该插件将为您完成所有自动完成甚至建议 UI(您只需将其指向文本框),并且您可以指定您只想自动完成位置(或仅美国县,或其他)。它可能有点以美国为中心,但听起来这适合您的特定用例。
Rather than maintaining your own database, I'd suggest you check out the Freebase Suggest plugin for jQuery. See this similar question.
That plugin will do all the auto-completion and even the suggestion UI for you (you just point it to a text box) and you can specify that you just want to auto-complete locations (or only US counties, or whatever). It might be a little US-centric, but it sounds like that will work for your particular use case.