不同国家、州、地理位置的动态下拉列表? [英] Dynamic drop down list for different countries, states, geographic locations?

查看:30
本文介绍了不同国家、州、地理位置的动态下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让我的用户输入他们的城市、州和国家.但我的困境是如何动态管理它,以便我可以在正确拼写和格式的同时控制输入的内容.

I am having my users to enter their city, state, and country. But my dilemma is how to manage it dynamically so that I can control what is entered while having correct spelling and formatting.

例如,我目前为每个州都有一个静态下拉列表.

For instance, I currently have a static drop down for each state.

<select>
     <option name="state" value="AL">Alabama</option>
     <option name="state" value="AK">Alaska</option>
     <option name="state" value="AZ">Arizona</option>
     <option name="state" value="AR">Arkansas</option>
     <option name="state" value="CA">California</option>
     ....
 </select>

这显然工作正常,但如果用户不在美国,则根本无法扩展.它在不同的国家和城市方面也存在不足.我曾想过使用文本字段,然后将它们保存在一个单独的数据库中,并使用 JQuery 自动完成插件来生成列表,但这似乎不是最好的方法.

This works fine obviously, but doesn't scale at all if the user is outside the US. It also falls short in regards to different countries and cities. I have thought of using text fields, then saving them in a separate database and using the JQuery autocomplete plugin for generating the list but it doesn't seem like the best way to do it.

推荐答案

好的,几个小时后我写了一个基于 MySQL 世界数据库的应用程序:MySQL 世界设置

Ok so after several hours I've written an application based on the MySQL world database: MySQL world Setup

整个应用程序的代码太大了,无法给出答案,因此我将为每个单独的文件提供 Pastebin 链接,以及指向脚本工作示例的链接和 Zip 存档的下载链接.

The code for the entire application is way to large to put in an answer so I'll provide Pastebin links for each seperate file, aswell as a link to a working example of the script and a download link for the Zip archive.

我确信代码可以进一步改进,但我会把它留给你.

I'm sure the code can be improved further, but I'll leave that up to you.

要求:MySQL世界数据库/jQuery

Requirements: MySQL world Database / jQuery

  1. index.html:index.html
  2. style.css:style.css
  3. country.js:country.js
  4. dbconnect.php:dbconnect.php
  5. get_country.php:get_country.php
  6. get_states.php:get_states.php
  7. get_city.php:get_city.php
  8. get_data.php:get_data.php

工作示例:

  1. 国家、州、城市选择器

Zip 存档下载(不包括数据库!):

  1. selector.zip(目前已关闭)
  2. 以上文件的病毒>
  1. selector.zip (currently down)
  2. Virus Total Analysis of above file

由于对这个问题的普遍要求,我正在编写更新的脚本.很快就会添加.

I'm working on an updated script due to the popular demands on this question. It will be added soon.

这篇关于不同国家、州、地理位置的动态下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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