,我要做的就是点击“+”的时候触发一次事件,但是在别的"+"号那里可以用,不懂我的问题,可以在回复中说
function onclickBusiness(id){
if(id){
var xmlhttp=create();
xmlhttp.open("post","servlet/AjaxService");
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
        if(xmlhttp.status==200){
var doc=xmlhttp.responseXML.documentElement;
var rows = doc.getElementsByTagName("row");
var div = document.createElement("div");
div.setAttribute("style","margin-left:140px;font-size:12px;");
var imgid=$(id);//得到在那里在实现一个层
for(var i = 0;i<rows.length;i++){
var r = rows[i];//得到行
var i1=r.childNodes[0].firstChild.nodeValue;//得到编号
var i2=r.childNodes[1].firstChild.nodeValue;//得到名称
var i3=r.childNodes[2].firstChild.nodeValue;//得到父编号
var p=document.createElement("p");
var input =document.createElement("input");
input.value=i2;
input.name="checks";
p.setAttribute("style","margin-top:3px;");
input.type="checkbox";
p.innerHTML=i2;
div.appendChild(p);
p.appendChild(input);
$(id).style.display="block";
}
alert(i1);
imgid.appendChild(div);
}else{
alert("错误:"+xmlhttp.status);
};
};
};
xmlhttp.send("m=selectBusiness&&id="+id);

}

}
只是我的代码

解决方案 »

  1.   


    function onclickBusiness(id){
    if(id){
    var xmlhttp=create();
    xmlhttp.open("post","servlet/AjaxService");
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    xmlhttp.onreadystatechange=function(){
    if(xmlhttp.readyState==4){
            if(xmlhttp.status==200){
    var doc=xmlhttp.responseXML.documentElement;
    var rows = doc.getElementsByTagName("row");
    var div = document.createElement("div");
    div.setAttribute("style","margin-left:140px;font-size:12px;");
    var imgid=$(id);//得到在那里在实现一个层
    for(var i = 0;i<rows.length;i++){
    var r = rows[i];//得到行
    var i1=r.childNodes[0].firstChild.nodeValue;//得到编号
    var i2=r.childNodes[1].firstChild.nodeValue;//得到名称
    var i3=r.childNodes[2].firstChild.nodeValue;//得到父编号
    var p=document.createElement("p");
    var input =document.createElement("input");
    input.value=i2;
    input.name="checks";
    p.setAttribute("style","margin-top:3px;");
    input.type="checkbox";
    p.innerHTML=i2;
    div.appendChild(p);
    p.appendChild(input);
    $(id).style.display="block";
    }
    alert(i1);
    imgid.appendChild(div);
    }else{
    alert("错误:"+xmlhttp.status);
    };
    };
    };
    xmlhttp.send("m=selectBusiness&&id="+id);}}能不能把代码整理一下 
      

  2.   

    你判断下容器是否有内容不就行了,没有就执行ajax,有就返回function onclickBusiness(id) {
        if (id) {
            var imgid = $(id); //得到在那里在实现一个层//////////获取容器的地方钓上来
            if (imgid.innerHTML != '') return////已经执行过ajax有内容,直接返回
            var xmlhttp = create();
            xmlhttp.open("post", "servlet/AjaxService");
            xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
                        var doc = xmlhttp.responseXML.documentElement;
                        var rows = doc.getElementsByTagName("row");
                        var div = document.createElement("div");
                        div.setAttribute("style", "margin-left:140px;font-size:12px;");
                        //var imgid = $(id); //得到在那里在实现一个层//////
                        for (var i = 0; i < rows.length; i++) {
                            var r = rows[i]; //得到行
                            var i1 = r.childNodes[0].firstChild.nodeValue; //得到编号
                            var i2 = r.childNodes[1].firstChild.nodeValue; //得到名称
                            var i3 = r.childNodes[2].firstChild.nodeValue; //得到父编号
                            var p = document.createElement("p");
                            var input = document.createElement("input");
                            input.value = i2;
                            input.name = "checks";
                            p.setAttribute("style", "margin-top:3px;");
                            input.type = "checkbox";
                            p.innerHTML = i2;
                            div.appendChild(p);
                            p.appendChild(input);
                            $(id).style.display = "block";
                        }
                        alert(i1);
                        imgid.appendChild(div);
                    } else {
                        alert("错误:" + xmlhttp.status);
                    };
                };
            };
            xmlhttp.send("m=selectBusiness&&id=" + id);    }}
      

  3.   

    function onclickBusiness(id,obj){
    ......//
        obj.onclick=null;
    }
    给所有+元素对象号都写   xxx.onclick=function(){var id=this.id;onclickBusiness(id,this);}
    ok了