【发布时间】:2012-02-10 11:21:32
【问题描述】:
我一直在寻找如何在 onchange 中放置多个函数,我发现了类似的内容,例如:onchange = "function1(); function2();"。
我的问题是我遵循了示例的内容,但只有函数 1 工作,函数 2 不工作。 如果我不这样做 onchange = "function2(); function1();",只有函数 2 工作,函数 1 不工作,一样。
有什么想法吗? 谢谢。
函数,我用的是Ajax:
function1(test)
{
var kode = test.value;
if (!kode) return;
xmlhttp.open('get', '../template/get_name-opr.php?kode='+kode, true);
xmlhttp.onreadystatechange = function() {
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
{
//alert(kode);
document.getElementById("code").innerHTML = xmlhttp.responseText;
}
return false;
}
xmlhttp.send(null);
}
function2(test)
{
var kode = test.value;
if (!kode) return;
xmlhttp**1**.open('get', '../template/get_name2-opr.php?kode='+kode, true);
xmlhttp**1**.onreadystatechange = function() {
if ((xmlhttp**1**.readyState == 4) && (xmlhttp**1**.status == 200))
{
//alert(kode);
document.getElementById("code2").innerHTML = xmlhttp**1**.responseText;
}
return false;
}
xmlhttp**1**.send(null);
}
为了解决我的问题,我创建了两个不同的 xmlhttp。 (xmlhttp 和 xmlhttp1)。
【问题讨论】:
-
您是否在任何函数上看到任何 JavaScript 错误?
-
@ShashankKadne Hummm.. 我不知道它是否调用错误,我在萤火虫中看到它说(函数的结果)for function1“localhost/template/get_name-opr.php?kode=f Aborted(所有字体为红色) , 表示没有响应,没有结果),function2“localhost/template/get_name-opr.php?kode=f”(这是得到响应的,确实有结果)。就是这样!我很困惑(=,=)“a。
-
查看错误控制台是否有错误(工具>错误控制台)
-
没有任何错误,只是在控制台中得到了我上面提到的两个结果。