我試圖在窗體中進行級聯選擇,但我無法使其工作。看來我的select元素中的onChange()不會觸發。onChange()不會觸發
php的
$flight_sql = "SELECT * FROM wp_flr_flights";
$flight_result = mysql_query($flight_sql);
echo '<select name="location" id="select-location onChange="changeSecond(this.value)">';
echo '<option value="">Select</option>';
while ($flt_loc_rows = mysql_fetch_assoc($flight_result)) {
$loc_id = $flt_loc_rows["location_id"];
$loc_name = $flt_loc_rows["location_name"];
echo '<option value="'.$loc_id.'">'.$loc_name.'</option>';
}
echo '</select>';
的JavaScript
function changeSecond(first){
alert('dasda');
var xmlhttp;
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){
var res=xmlhttp.responseText;
document.getElementById("second").innerHTML=res;
}
}
xmlhttp.open("GET","reservations-plane.php?first="+first,true);
xmlhttp.send();
}
保留-plane.php
global $wpdb, $page_url;
$location=mysql_real_escape_string($_REQUEST["first"]);
echo $userid.'ddd';
$flight_sql = "SELECT ".$location." FROM wp_flr_flights GROUP BY ".$location;
$flight_result = mysql_query($flight_sql);
echo '<select name="plane_type_choose">';
while ($flt_plane_rows = mysql_fetch_row($flight_result)) {
$plain_id = $flt_plane_rows["plane_id"];
$plane_type = $flt_plane_rows["plane_type"];
echo '<option value="'.$flt_plane_rows[0].'">'.$flt_plane_rows[0].'</option>';
}
echo '</select>';
'$ function changeSecond(first){'只是複製/粘貼錯字?因爲它應該是函數changeSecond(...'。 – Zeta
它看起來你錯過了你的id屬性後的結尾quoutes(onchange觸發器之前) – jtheman
當問一個Javascript問題時,顯示'php'或''''''''''''''''''''我們唯一需要看到的是呈現的'HTML'和'Javascript'.也就是說,看起來像其他評論可以解決您的問題 –