【发布时间】:2014-07-18 22:20:30
【问题描述】:
所以我有这个简单的 AJAX 示例要修改,所以当我在选择框中更改年份时,我希望它对多个 div 生效,而不仅仅是具有 ID 的那个。有什么解决办法吗?我在想 getelementsbyclassname,但它没有显示任何内容。
<html>
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","proba.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onChange="showUser(this.value)">
<option value="">Choose year:</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
</form>
<br>
<div id="txtHint"><b> - </b></div>
<p> </p>
</body>
</html>
【问题讨论】:
标签: javascript php mysql ajax drop-down-menu