禮拜五下午公司網站維護的同事問我怎樣實現一個功能,一個提
交頁上有兩個select,第二個select根據第一個select變,我的
第一念頭就是用AJax!
test.htm:
<Html>
<head>
<script type="text/Javascript">
var XMLhttp;
function GetContent(param)
{
url="";
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
if(param==0)
{
url="zfive5.htm";
}
else
{
url="zfive6.htm";
}
XMLhttp.open("GET",url);
XMLhttp.onreadystatechange=oncallback;
XMLhttp.send(url);
}
function oncallback()
{
if(XMLhttp.readyState==4)
{
if(XMLhttp.status==200)
{
document.getElementById("zfive5").innerHtml=XMLhttp.responseText;
}
}
}
</script>
</head>
<body>
<form method="get" id="zf5" action="#">
<table>
<tr>
<td>
Type:<select id="name1" >
<option value="1" selected>1.zfive5</option>
<option value="2">2.zfive6</option>
</select>
</td>
<td id=zfive5>
Person:<select id="name2" NAME="name2">
<option value="zfive5">zfive5</option>
<option value="zqqa">zQQa</option>
</select>
</td>
</tr>
</table>
</form>
</body>
</Html>
zfive5.htm:
Person:<select id="name2">
<option value="zfive5">zfive5</option>
<option value="zqqa">zQQa</option>
</select>
zfive6.htm:
Person:<select id="name2">
<option value="zfive6">zfive6</option>
<option value="zqqa">zQQa</option>
</select>