JS级联下拉框

//Ajax级联获取SDK
function GetDropDownList(parent_ddlID, fill_dllID, url, param) {
    this.pId = parent_ddlID;  //主下拉框name
    this.cId = fill_dllID;    //级联下拉框name
    this.URL = url;           //获取数据路径
    this.Paramer = param;     //参数
}
GetDropDownList.prototype.Inits = function (current) {
    var $ddl = $("select[name$=" + this.pId.toString() + "]");
    var $ddlSDKs = $("select[name$=" + this.cId.toString() + "]");
    $ddl.focus();
    $ddl.bind("change keyup", function () {
        if ($(this).val() != "0") {
            current.loadSDKList(current, $("select option:selected").val());
            $ddlSDKs.fadeIn("slow");
        } else {
            //$ddlSDKs.fadeOut("slow");
            $ddlSDKs.children("option").remove();
            $ddlSDKs.append($("<option></option>").val("0").html("不限"));
        }
    });
}
GetDropDownList.prototype.loadSDKList = function (current, selectedItem) {
    $.ajax({
        type: "get",
        url: this.URL,
        data: this.Paramer + "=" + selectedItem,
        dataType: "json",
        async: true,
        success: function (ret) {
            current.printSDKList(ret);
        }
    });
}
GetDropDownList.prototype.printSDKList = function (data) {
    $("select[name$=" + this.cId.toString() + "] > option").remove();
    for (var i = 0; i < data.length; i++) {
        $("select[name$=" + this.cId.toString() + "]").append(
                        $("<option></option>").val(data[i].Value).html(data[i].Text)
                   );
    }
}

 

//调用

//var d = new GetDropDownList(‘主下拉框name‘, ‘级联下拉框name‘, ‘获取数据路径‘, ‘传递给调用路径的参数‘);
//d.Inits(d);

GetDropDownLis

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。