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

转载于:https://www.cnblogs.com/hucaihao/p/3554688.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值