问题描述
我有我的用户输入他们的城市,州和国家。但我的困境是如何动态地管理它,这样我可以控制,同时具有正确的拼写和格式的输入的内容。
比如说,我现在有一个静态下拉为每个状态。
<选择>
<选项名=状态值=AL>阿拉巴马州和LT; /选项>
<选项名=状态值=AK>阿拉斯加< /选项>
<选项名=状态值=AZ>亚利桑那< /选项>
<选项名=状态值=AR>阿肯色州< /选项>
<选项名=状态值=CA>&加州LT; /选项>
....
< /选择>
这工作得很好很明显,但如果用户是在美国以外没有刻度的。它还达不到的问候不同的国家和城市。我曾经想过使用文本字段,然后将其保存在一个单独的数据库,并使用jQuery自动完成插件生成的列表中,但它似乎不喜欢这样做的最佳方式。
好了,所以几个小时后,我已经写了基于MySQL的数据库,世界上的应用程序:的
在code为整个应用程序的方式来大放一个答案,所以我会为每一个单独的文件中提供Pastebin链接的,藏汉为纽带,以脚本的工作示例和下载链接ZIP文件。
我敢肯定,code可以进一步提高,但我会离开,你。
要求:MySQL的世界数据库/ jQuery的
- index.html的:
- 的style.css:
- country.js:
- dbconnect.php:
- get_country.php:
- get_states.php:
- get_city.php:
- get_data.php:
工作示例:
Zip文件下载(DB不包括在内!):
我工作的一个更新脚本,由于在这个问题上流行的需求。据我们会尽快添加。
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
- index.html: index.html
- style.css: style.css
- country.js: country.js
- dbconnect.php: dbconnect.php
- get_country.php: get_country.php
- get_states.php: get_states.php
- get_city.php: get_city.php
- get_data.php: get_data.php
Working Example:
Zip Archive Download (DB NOT included!):
- selector.zip (currently down)
- 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.
这篇关于动态下拉列表中针对不同的国家,州,地理位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!