注意:大部分时间系统只显示showhistory()函数输出
我现有的代码
.............................................
<select name="po_no" onchange="showsize(this.value);showhistory(this.value);">
............................................... .........
<script>
function showhistory(str)
{if (str=="")
{
document.getElementById("txtHistory").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("txtHistory").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethistory2.php?s="+str,true);
xmlhttp.send();
}
</script>
<script>
function showsize(str)
{
if (str=="")
{
document.getElementById("sizeHint1").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp1=new XMLHttpRequest();
}
else
{
xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp1.onreadystatechange=function()
{
if (xmlhttp1.readyState==4 && xmlhttp.status==200)
{
document.getElementById("sizeHint1").innerHTML=xmlhttp1.responseText;
}
}
xmlhttp1.open("GET","getsize5.php?q="+str,true);
xmlhttp1.send();
}
</script>
答案 0 :(得分:2)
您通过重新分配方法showHistory()来覆盖onChange的第一个值(showSize())。要避免这种情况,请将其包装到一个函数中,该函数调用两个调用,如下所示:
function showAll(strValue){
SHOWALL(strValue中);
showSize(strValue中);
}
最后调用如下所示:
<select name="po_no" onchange="showAll(this.value);">
答案 1 :(得分:1)
在第一个函数
成功时调用第二个函数<select name="po_no" onchange="showhistory(this.value);">
<script>
function showhistory(str)
{if (str=="")
{
document.getElementById("txtHistory").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("txtHistory").innerHTML=xmlhttp.responseText;
showsize(str);
}
}
xmlhttp.open("GET","gethistory2.php?s="+str,true);
xmlhttp.send();
}
function showsize(str)
{
if (str=="")
{
document.getElementById("sizeHint1").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp1=new XMLHttpRequest();
}
else
{
xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp1.onreadystatechange=function()
{
if (xmlhttp1.readyState==4 && xmlhttp.status==200)
{
document.getElementById("sizeHint1").innerHTML=xmlhttp1.responseText;
}
}
xmlhttp1.open("GET","getsize5.php?q="+str,true);
xmlhttp1.send();
}
</script>