//参数:postUrl控制器路径
//parIndex,第 一个属性字段名
//parName  第二个属性字段名
//divId    显示层Id
//hiddId   表单域Id
//txtId    要隐藏文本框Id
var weeBox = null;
var parmIndex = null;
var parmName = null;
var divIds = null;
var hiddIds = null;
var txtIds = null;
function CategoryShow(postUrl, parIndex, parName, divId, hiddId, txtId) {
    parmIndex = parIndex;
    parmName = parName;
    divIds = divId;
    hiddIds = hiddId;
    txtIds = txtId;
    if (weeBox == null) {
        weeBox = $.weeboxs.open("<div style='padding:20px 5px;'>科室类型详细信息正在读取中......</div>", { title: "日志浏览", showOk: false });
    } else {
        weeBox._content = "<div style='padding:20px 5px;'>科室类型详细信息正在读取中......</div>";
        weeBox.options.showLeft = true;
        weeBox.options.showButton = true;
        weeBox.showOk = false;
        weeBox.ReSet();
    }
    $.post(postUrl, { id: 106 }, function (data) {
        if (data != "{}") {
            data = new Function("return " + data + "")();
            LoadList(data);
        } else {
            weeBox._content = "<div style='padding:20px 5px;'>科室类型详细信息读取失败......</div>";
        }
    }, "text");}
var list = new Array();
var selectList = new Array();
function LoadList(data) {
    for (var i = 0; i < data.DT.length; i++) {
        list.push("({Index:\"" + data.DT[i][parmIndex] + "\",ShowName:\"" + data.DT[i][parmName] + "\"})");
    }
    tch(list);
}function getBool(strHtml,index,names) {
    for (var i = 0; i < selectList.length; i++) {
        if (index == eval(selectList[i]).Index) {
            strHtml += "<li><input type=\"checkbox\" name=\"cate\" checked=\"checked\" value='" + index + "' onchange=\"checked_checkbox(this,'" +
    parmIndex + "','" + parmName + "','" + divIds + "','" + hiddIds + "','" + txtIds + "')\" />" + names + "</li>";
            return strHtml;
        }
    }
    strHtml += "<li><input type=\"checkbox\" name=\"cate\" value='" + index + "' onchange=\"checked_checkbox(this,'" +
    parmIndex + "','" + parmName + "','" + divIds + "','" + hiddIds + "','" + txtIds + "')\" />" + names + "</li>";
    return strHtml;
}function tch(list) {
    var strHtml = "<ol><li><input type=\"text\" name=\"txtSearch\" Id=\"txtSearch\" /><input type=\"button\" value=\"搜索\" onclick=\"cli('" +
    parmIndex + "','" + parmName + "','" + divIds + "','" + hiddIds + "','" + txtIds + "')\" /></li>";
    for (var i = 0; i < list.length; i++) {
        strHtml = getBool(strHtml,eval(list[i]).Index, eval(list[i]).ShowName);
    }
    strHtml += "</ol>";
    weeBox._content = strHtml;
    weeBox.options.showLeft = false;
    weeBox.options.width = 700;
    weeBox.options.height = 400;
    weeBox.options.showButton = true;
    weeBox.showOk = false;
    weeBox.ReSet();}
function checked_checkbox(ob) {
    if (ob.checked) {
        selectList.push(getList(ob.value));
        show();
    } else {
        exList(ob.value);
    }}function show() {
    var strDiv = "<ol>";
    var strCode = "";
    for (var i = 0; i < selectList.length; i++) {
        strDiv += "<li><a href=\"javascript:\exList('" + eval(selectList[i]).Index + "','" +
    parmIndex + "','" + parmName + "','" + divIds + "','" + hiddIds + "','" + txtIds + "')\" title=\"删除这一项\">" + eval(selectList[i]).ShowName + "</a></li>";
        strCode += eval(selectList[i]).Index + ",";
    }
    strDiv += "</ol>";
    document.getElementById(divIds).innerHTML = strDiv;
    document.getElementById(hiddIds).value = strCode;
    if (strCode != "") {
        document.getElementById(txtIds).style.display = 'none';
    } else {
        document.getElementById(txtIds).style.display = 'block';
    }
}function exList(index) {
    var ovList = new Array();
    for (var i = 0; i < selectList.length; i++) {
        if (index != eval(selectList[i]).Index) {
            ovList.push(selectList[i]);        }    }
    selectList = ovList;
    show();
}function getList(index) {
    for (var i = 0; i < list.length; i++) {
        if (index == eval(list[i]).Index) {
            return list[i];
        }
    }
}function cli() {
    var str = document.getElementById("txtSearch").value;
    if (str == "") {
        str = " ";
    }
    var lists = new Array();
    for (var i = 0; i < list.length; i++) {
        if (list[i].indexOf(str) > 0) {
            lists.push(list[i]);
        }
    }
    tch(lists);
}这实现的是一个弹出窗,页面只用调CategoryShow这个方法 
如果只有一个按钮的话,可以实现,但是,页面有十多个按钮
这样一来,我那定义的变量就全乱了,
听说可以用定义对象解决这个问题,可以没这么用过,语法用法都不知道,网上找的自己一用不出效果
求解决方案,最好是完整的,,

解决方案 »

  1.   

    CategoryShow(postUrl, parIndex, parName, divId, hiddId, txtId)
    加个button ID区分撒 要不传Button过去在变量赋值之前,清空所有变量值,恢复为刚加载的状态。楼主定义的变量乱在那?
      

  2.   

    ajax 异步的 传值  或者 写一个 触发 
      

  3.   

    不使用全局变量。全部传参就可以了参数全部靠传
    function LoadList(data,parmIndex,parmName) {
        for (var i = 0; i < data.DT.length; i++) {
            list.push("({Index:\"" + data.DT[i][parmIndex] + "\",ShowName:\"" + data.DT[i][parmName] + "\"})");
        }
        tch(list);
    }
      

  4.   

    唉。我加了3个方法 ,,,2个集合,,,,外加一次ajax查询,,勉强算是解决了吧。。
    唉,,为什么贴子会沉呢