簡體   English   中英

IE 不使用 onChange Javascript、PHP 呈現 select 選項

[英]IE not rendering select options using onChange Javascript, PHP

我正在使用 JavaScript onChange 、 MySQL 和 PHP 來顯示從縣列表中填充的城鎮列表中的分支機構地址。

它在除 IE(任何版本)之外的所有瀏覽器中都能正常工作。 在 IE 中,我得到的只是一個空白 select 選項。

Javascript

function getCounty(strURL) {
    if (strURL==="") {
        document.getElementById("branch").innerHTML="";
        return;
    }
    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("branch").innerHTML=xmlhttp.responseText;
            //alert(document.getElementById("branch").innerHTML=xmlhttp.responseText);
        }
    };
    xmlhttp.open("GET",strURL,true);
    xmlhttp.send(null);
}

function getBrach(strURL) {
    if (strURL==="") {
        document.getElementById("branch-addr").innerHTML="";
        return;
    }
    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("branch-addr").innerHTML=xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET",strURL,true);
    xmlhttp.send(null);
}

Forms

<form method="post" id="addr-finder" action="">
<div class="county">
    <label>Choose County</label>
    <select name="county" id="county" onChange="getCounty('inc/findcity.php?c='+this.value)">
        <option value="Select County">Select County</option>
<?php
while($row = $result->fetch_object()) {
    echo '<option value="'.$row->address_5.'">'.$row->address_5.'</option>';
}
?>
    </select>
</div>
<div class="branch">
    <label>Choose Branch</label>
    <select name="branch" id="branch" onChange="getBrach('inc/findbranch.php?t='+this.value)">
        <option>--</option>
    </select>
</div>
</form>

PHP

<?php
include("cfg.php");
include("functions.php");

$county = $_REQUEST['c'];
$result2 = get_town($county);
?>
    <option>Select Town</option>
<?php 
while($row2 = $result2->fetch_object()) {
?>
    <option value="<?php echo $row2->address_4 ; ?>"><?php echo $row2->address_4; ?></option>
<?php
}
?>

我以快速而骯臟的方式做到了。
使用onclick代替。
你甚至可以兩者都做,我做了幾個地方讓一些移動瀏覽器工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM