将2个几乎相同的函数加入1

function showRole(str,x)
        {
            if (str=="")
              {
              document.getElementById("txtHintrole"+x+"").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("txtHintrole"+x+"").innerHTML=xmlhttp.responseText;
                }
              }

            xmlhttp.open("GET","http://localhost/tes/index.php/form/role/"+str,true);
            xmlhttp.send();
        }
function showUser(str,x)
        {
            if (str=="")
              {
              document.getElementById("txtHint"+x+"").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"+x+"").innerHTML=xmlhttp.responseText;
                }
              }

            xmlhttp.open("GET","http://localhost/tes/index.php/form/hint/"+str,true);
            xmlhttp.send();
        }

我可以加入这2个功能为1,因为我需要他们两个来显示数据,我不知道如何设置2功能

newcell.childNodes [0] .setAttribute( “平变化”, “showUser(THIS.VALUE,” + XX + “);”);


我猜你想在onchange上调用两个函数。 尝试这个:

newcell.childNodes[0].setAttribute("onchange",function(){
    showUser(this.value,"+xx+");
    secondFunction();
});

或者因为您标记了此jQuery,请使用jQuery方法:

$(newcell.childNodes[0]).change(function(){
    showUser(this.value,"+xx+");
    secondFunction();
});
链接地址: http://www.djcxy.com/p/22325.html

上一篇: join 2 same almost same function into 1

下一篇: PHP and AJAX login form