$(document).ready(function () { ChangeProvince(); ChangeCities(); }); //更改省份选项,获取该省的所有城市,绑定到市级下拉框 function ChangeProvince() { GetList("Cities",$("#ddl_Province option:selected").val(),"ddl_Cities"); } //更改市级选项,获取该市的所有区(县),绑定到区(县)级下拉框 function ChangeCities() { GetList("Districts",$("#ddl_Cities option:selected").val(),"ddl_Districts"); } //获取下拉框选项内容 function GetList(XmlName,ID,SelectID) { $.ajax({ url: "/Account/GetJson/?XmlName=" + XmlName + "&ID=" + ID,type: "GET",dataType: "text",success: function (result) { $("#" + SelectID).html(result); } }); }
此时,当执行ready()时会发现,在ChangeCities()函数中$("#ddl_Cities option:selected").val()是取不到值的。
$(document).ready(function () { ChangeProvince(); $("#ddl_Province").ajaxComplete(function () { ChangeCities(); }); });