您好我正在尝试在HTML
中添加此查询此选项<select name="state" onchange="getCity(<?=$country?>,this.value)">
<option>Select State</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['id']?>><?=$row['statename']?></option>
<? } ?>
</select>
我的HTML代码的这一部分
<td ><select name="state" id="statediv">
<option>Select Country First</option>
</select></td>
使用此步骤
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('statediv').innerHTML(req.responseText);
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
就像innerHTML不起作用一样,我使用了appendchild,但是只将选择输出放在一行而不是在选择列表选项中就像我想要的那样你在下一个代码中看到的任何想法,我可以使用的其他选项将信息放在选择选项值中。
// so long as obj has children, remove them
while(document.getElementById('statediv').firstChild) document.getElementById('statediv').removeChild(document.getElementById('statediv').firstChild);
// update the contents of the element with a new node
var optionElement = document.createElement("option");
optionElement.innerHTML=req.responseText;
document.getElementById('statediv').appendChild(optionElement);