这是我的代码。看到注释掉的那一行。当元素ID(这是一个范围)是硬编码的,它的工作原理。当通过连接传递给stateChanged的变量创建id时,它不起作用。我不允许将变量传递给stateChanged吗?怎么了?在xmlhttp.onreadystatechange函数中,如何传递要编辑的ID的名称?
function multiplePassportPoints(id, counter)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="addmorepoints.php";
url=url+"?id="+id+"&c="+counter;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged(id,counter);
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged(id, counter)
{
if (xmlhttp.readyState==4)
{
//THIS WORKS (assuming id is 99 and counter is 5:
//document.getElementById("99_5").innerHTML += xmlhttp.responseText;
//BUT I NEED IT TO WORK LIKE THIS:
document.getElementById(studentID+"_"+counter).innerHTML += xmlhttp.responseText;
}
}
谢谢!
岩石上!有用!谢谢。 – Jen 2009-09-15 06:06:01
+1。但是我希望你能解释一下'xmlhttp.onreadystatechange = stateChanged(id,counter);'实际上是调用'stateChanged(id,counter)',并将返回值赋给'onreadystatechange'而不是分配函数本身。 – 2009-09-15 15:57:51