标签:
function area() { _url = "/ashx/DropDownControl.ashx"; _swType = "GetArea"; _z = ["#province", "#city", "#conty"]; _zo = ["#province > option[value!=-1]", "#city > option[value!=-1]", "#conty > option[value!=-1]"]; this.BindChange = function () { _load(0, null); $(_z[0]).change(function () { _load(1, null); $(_zo[2]).remove() }).change(); $(_z[1]).change(function () { _load(2, null) }) }; this.GetArea = function () { var a = $(_z[2]).val(); a = a == "-1" ? $(_z[1]).val() : a; a = a == "-1" ? $(_z[0]).val() : a; return a }; this.SetArea = function (r) { if (r.length > 0) { if (r.length == 2) { $(_z[0]).val(r).change(); $(_z[1]).change(); $(_zo[2]).remove() } else { if (r.length == 4) { var p = r.substr(0, 2); $(_z[0]).val(p); _load(1, function () { $(_z[1]).val(r); $(_zo[2]).remove() }) } else { if (r.length == 6) { var p = r.substr(0, 2); var c = r.substr(0, 4); $(_z[0]).val(p); _load(1, function () { $(_z[1]).val(c); _load(2, function () { $(_z[2]).val(r) }) }) } } } } }; this.ResetArea = function () { $(_z[0] + " > option:first").attr("selected", "selected"); $(_z[0]).change(); $(_z[1]).change() }; _load = function (t, c) { var guid = t == 0 ? "" : t == 1 ? $(_z[0]).val() : $(_z[1]).val(); if (guid != "-1") { $(_zo[t]).remove(); var obj = $(_z[t]); JQueryPost(_url, { swType: _swType, guid: guid }, function (r) { r = eval("(" + r + ")"); for (var i = 0; i < r.length; i++) { obj.append("<option value=‘" + r[i].Value + "‘>" + r[i].Text + "</option>") } if (c != null) { setTimeout(function () { c() }, 100) } }) } else { if (c != null) { c() } } } };
使用方法:var ar = new area();ar.SetArea(result.areaCode);
获取选中的地址:ar.GetArea();
注意:各级联下拉框id值已经固定,不可更改。
标签:
原文地址:http://www.cnblogs.com/maomao999/p/4831322.html