读书人

新手 关于AJAX一个事件触发两个方法的

发布时间: 2012-05-08 22:09:41 作者: rapoo

新手 关于AJAX一个事件触发两个方法的问题!~
代码如下,我想通过下拉列表的选择来控制另外两个“id”的内容?但是这样调用的话只有第二个生效,第一个不生效?

JScript code
function showType(str){    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("coachType").innerHTML = xmlhttp.responseText;        }    }    xmlhttp.open("POST", "findType.c?s="+str, true);    xmlhttp.send();    showType2(str);}function showType2(str){    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("subjectId").innerHTML = xmlhttp.responseText;        }    }    xmlhttp.open("POST", "findType2.c?s="+str, true);    xmlhttp.send();}

HTML code
<select id="coachId" name="coachId" onchange="showType(this.value),showType2(this.value)"></select><td><div id="coachType"></div></td><td><select id="subjectId" name="subjectId"><option>请选择教练</option></select></td>


[解决办法]
这个是IE 的bug,http://www.cnblogs.com/icewee/articles/2017682.html

读书人网 >Ajax

热点推荐