没有数据库方案很难回答,但这里有。
假设您的数据库看起来像
Countrys
+--------------+
| New Zealand |
+--------------+
| Australia |
+--------------+
| India |
+--------------+
Towns
Country Town
+--------------+---------------+
| NZL | Auckland |
+--------------+---------------+
| NZL | Wellington |
+--------------+---------------+
| NZL | Christchurch |
+--------------+---------------+
| AU | Sydney |
+--------------+---------------+
| AU | Wagawaga |
+--------------+---------------+
| AU | Brisbane |
+--------------+---------------+
| IN | Mumbai |
+--------------+---------------+
……等等等等
首先选择
<select onchange ="town()" id="country">
<option value = "NZ">New Zealand</option>
<option value = "AU">Australia</option>
<option value = "IN">India</option>
</select>
第二个
<select id="towns"></select>
Javascript
function town()
{
var town = $('#country').val()
$.ajax({
type: "POST",
url: "http://yourserver/rpc.php",
data: { method: 'get_towns'},
dataType: "json",
timeout: 10000, // in milliseconds
success: function(data) {
$("#towns".html(data.towns)
},
error: function(request, status, err) {
if(status == "timeout") {
$.ui.hideMask();
alert('This is taking too long. You could try again now, or wait and try again later.');
}
}
});
}
从您的数据库返回 json 中的城镇