所有你需要的是一個ajax請求。試試這個模板,它不需要jQuery的
的Javascript
function ajax_request(destination_url, parameters, output_id) {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById(output_id).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("POST", destination_url, false);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(parameters);
}
HTML
<select name="state" onselect="ajax_request(get_cities.php, this.value, city_list)" />
<option value="1">Pensilvania</option>
<option value="2">New York</option>
<option value="3">Florida</option>
</select>
<select id="city_list" name="city" />
</select>
你現在需要的,就是寫get_cities.php
。在這個文件中,根據您使用ajax發佈的州名,從MySQL表中獲取國家列表。
聽起來像你正在尋找[級聯下拉]框 – MikeM
我還沒有真正嘗試過任何東西,除了一個簡單的形式,我作爲一個樣本爲你剛纔看到。但它不是SELECT形式。 –