【发布时间】:2011-08-04 00:55:25
【问题描述】:
我对 AJAX 还很陌生,所以请原谅我。
我必须表格 - 第一个有效,但第二个无效,我不知道为什么。第一个 html 表单没有提交按钮,但第二个有。它们都使用相同的 javascript 函数。
<script type="text/javascript">
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","server_script.php?q="+str,true);
xmlhttp.send();
}
</script>
从1开始:
<form>
<select name="users" onchange="showUser(this.value)">
<option value="0001">0001</option>
0002
从 2 开始:
<form onsubmit="showUser(this.foo.value)">
<input type="foo" >
<input type="submit" >
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
【问题讨论】:
标签: javascript html ajax dom