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

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

问题描述

我有我的用户输入他们的城市,州和国家。但我的困境是如何动态地管理它,这样我可以控制,同时具有正确的拼写和格式的输入的内容。

比如说,我现在有一个静态下拉为每个状态。

 <选择>
     <选项名=状态值=AL>阿拉巴马州和LT; /选项>
     <选项名=状态值=AK>阿拉斯加< /选项>
     <选项名=状态值=AZ>亚利桑那< /选项>
     <选项名=状态值=AR>阿肯色州< /选项>
     <选项名=状态值=CA>&加州LT; /选项>
     ....
 < /选择>

这工作得很好很明显,但如果用户是在美国以外没有刻度的。它还达不到的问候不同的国家和城市。我曾经想过使用文本字段,然后将其保存在一个单独的数据库,并使用jQuery自动完成插件生成的列表中,但它似乎不喜欢这样做的最佳方式。


解决方案

好了,所以几个小时后,我已经写了基于MySQL的数据库,世界上的应用程序:的 MySQL的世界格局

在code为整个应用程序的方式来大放一个答案,所以我会为每一个单独的文件中提供Pastebin链接的,藏汉为纽带,以脚本的工作示例和下载链接ZIP文件。

我敢肯定,code可以进一步提高,但我会离开,你。

要求:MySQL的世界数据库/ 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

工作示例:


  • 国家,省份,城市选择

  • Zip文件下载(DB不包括在内!):

    <醇开始=10>
  • selector.zip (目前下跌)

  • 以上文件的病毒全分析

  • 我工作的一个更新脚本,由于在这个问题上流行的需求。据我们会尽快添加。

    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>
    

    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.

    解决方案

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

    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.

    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

    Working Example:

    1. Country, State, City selector

    Zip Archive Download (DB NOT included!):

    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天全站免登陆