首页 文章

将2个相同的功能加入1 [关闭]

提问于
浏览
-9
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(“onchange”,“showUser(this.value,”xx“);”);

1 回答

  • 1

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

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

    或者既然你标记了这个jQuery,那就用jQuery方式做吧:

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

相关问题