继一般实现之后,利用asp.net ajax在js上对面向对象的支持,在此实现了相同的功能。/// <reference name="MicrosoftAjax.js"/> Type.registerNamespace("FjdcHtmlUserControl"); FjdcHtmlUserControl.ShengShiQuSelect = function(shengSelect, shiSelect, quSelect, action) { this._shengSelect = $get(shengSelect); this._shiSelect = $get(shiSelect); this._quSelect = $get(quSelect); this._userContext = new Array(this._shengSelect, this._shiSelect, this._quSelect); this._action = action; } FjdcHtmlUserControl.ShengShiQuSelect.prototype = { setShengSelect: function() { this._userContext[3] = "ShengSelect"; FjdcWS.GetShengShiQu(this._action, null, this._dataBind, this._onError, this._userContext); }, setShiSelect: function() { this._userContext[3] = "ShiSelect"; var parameterValue = this._shengSelect.options[this._shengSelect.selectedIndex].value; switch(parameterValue) { case "710000": this.setSpecialCity(this._shiSelect, "台湾", "710000"); this.setSpecialCity(this._quSelect, "台湾", "710000"); break; case "810000": this.setSpecialCity(this._shiSelect, "香港", "810000"); this.setSpecialCity(this._quSelect, "香港", "810000"); break; case "820000": this.setSpecialCity(this._shiSelect, "澳门", "820000"); this.setSpecialCity(this._quSelect, "澳门", "820000"); break; default: FjdcWS.GetShengShiQu(this._action, parameterValue, this._dataBind, this._onError, this._userContext); } }, setQuSelect: function() { this._userContext[3] = "QuSelect"; var parameterValue = this._shiSelect.options[this._shiSelect.selectedIndex].value; FjdcWS.GetShengShiQu(this._action, parameterValue, this._dataBind, this._onError, this._userContext); }, setSpecialCity: function(selectID, mc, dm) { selectID.options[1] = new Option(mc, dm); selectID.selectedIndex = 1; }, _dataBind: function(result, userContext) { var selectID = null; switch(userContext[3]) { case "ShengSelect": selectID = userContext[0]; userContext[1].options.length = 1; userContext[2].options.length = 1; break; case "ShiSelect": selectID = userContext[1]; userContext[1].options.length = 1; userContext[2].options.length = 1; break; case "QuSelect": selectID = userContext[2]; break; } var i = 1; for(var item in result) { var option = new Option(result[item].MC,result[item].DM); selectID.options[i] = option; i++; } }, _onError: function(error) { alert(error.get_message()); } } FjdcHtmlUserControl.ShengShiQuSelect.registerClass("FjdcHtmlUserControl.ShengShiQuSelect"); // function GetShengShiQu(shengSelect, shiSelect, quSelect, action) { var getShengShiQu = new FjdcHtmlUserControl.ShengShiQuSelect(shengSelect, shiSelect, quSelect, action); switch(action) { case "GetSheng": getShengShiQu.setShengSelect(); break; case "GetShi": getShengShiQu.setShiSelect(); break; case "GetQu": getShengShiQu.setQuSelect(); break; } }