/*
|
城市区域JS
|
吴辉
|
20130417
|
|
*/
|
|
/*
|
1.城市区域
|
//页面使用
|
<div class="popupMenu" id="PCACCommon"></div>
|
<script type="text/javascript">
|
PCAC('<%=Province %>', '<%=City %>', '<%=County %>',"Name");//城市数据存名称用Name,存编号则空字符
|
</script>
|
|
//后台使用
|
//声明
|
public string Province = ""; //接收值 Request["selectProvince"].ToString2();
|
public string City = "";//接收值 Request["selectCity"].ToString2();
|
public string County = "";//接收值 Request["selectCounty"].ToString2();
|
|
//赋值
|
Province = model.Province.ToString2();
|
City= model.City.ToString2();
|
County = model.County.ToString2();
|
|
//接收
|
model.Province = Request["selectProvince"].ToString2();
|
model.City = Request["selectCity"].ToString2();
|
model.County = Request["selectCounty"].ToString2();
|
|
参数:省,市,区,数据类型(名称用Name,存编号则空字符)
|
*/
|
|
function PCACProvince(old_province, date_type) {
|
var PcacHtml = "<select id='selectProvince' name='selectProvince' keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select>";
|
$("#PCACCommon").html(PcacHtml);
|
PCACData(old_province, "", "", date_type);
|
}
|
|
function PCACCity(old_province, old_city, date_type) {
|
var PcacHtml = "<select id='selectProvince' name='selectProvince' keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select> <select id='selectCity' name='selectCity' keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select>";
|
$("#PCACCommon").html(PcacHtml);
|
PCACData(old_province, old_city, "", date_type);
|
}
|
|
function PCACCounty(old_province, old_city, old_county, date_type) {
|
var PcacHtml = "<select id='selectProvince' name='selectProvince' keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select> <select id='selectCity' name='selectCity' keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select> <select id='selectCounty' name='selectCounty' keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select>";
|
$("#PCACCommon").html(PcacHtml);
|
PCACData(old_province, old_city, old_county, date_type);
|
}
|
|
function PCAC(old_province, old_city, old_county, date_type) {
|
if (arguments.length == 2) {
|
PCACProvince(old_province, old_city);
|
return;
|
} else if (arguments.length == 3) {
|
PCACCity(old_province, old_city, old_county);
|
return;
|
} else if (arguments.length == 4) {
|
PCACCounty(old_province, old_city, old_county, date_type);
|
return;
|
}
|
}
|
|
|
function PCACData(old_province, old_city, old_county, date_type) {
|
try {
|
//加载省
|
$.ajax({
|
url: "/Pages/common/CommonAjax.aspx",
|
type: "POST",
|
dataType: "html",
|
data: { cityType: "province" },
|
global: false,
|
cache: false,
|
success: function (data) {
|
var myobj = null;
|
if (data != null && data != "" && data != undefined) {
|
myobj = eval('(' + data + ')');
|
}
|
var hasProvince = false;
|
if (myobj != null && myobj.length > 0) {
|
for (var i = 0; i < myobj.length; i++) {
|
var city_keyid = myobj[i].Keyid;
|
var city_name = myobj[i].Name;
|
var option = "";
|
|
if (!hasProvince && city_name == old_province) {
|
hasProvince = true;
|
}
|
if (date_type == "Name") {
|
option = "<option value = '" + city_name + "'>" + city_name + "</option>";
|
} else {
|
option = "<option value = '" + city_keyid + "'>" + city_name + "</option>";
|
}
|
$(option).appendTo($("#selectProvince"));
|
$("#selectProvince").attr("class", "fl");
|
|
$("#selectCity").attr("class", "fl ml5px");
|
|
$("#selectCounty").attr("class", "fl ml5px");
|
}
|
}
|
if (hasProvince) {
|
$("#selectProvince").val(old_province);
|
}
|
$("#selectProvince").change();
|
}
|
});
|
|
//加载市
|
$("#selectProvince").live("change", function () {
|
$.ajax({
|
url: "/Pages/common/CommonAjax.aspx",
|
type: "POST",
|
dataType: "html",
|
data: { old_province: $("#selectProvince").val(), cityType: "city", date_type: date_type },
|
global: false,
|
cache: false,
|
success: function (data) {
|
$("#selectCity").html("<option value=''>请选择</option>");
|
var myobj = null;
|
if (data != null && data != "" && data != undefined) {
|
myobj = eval('(' + data + ')');
|
}
|
var hasCity = false;
|
if (myobj != null && myobj.length > 0) {
|
for (var i = 0; i < myobj.length; i++) {
|
var city_keyid = myobj[i].Keyid;
|
var city_name = myobj[i].Name;
|
var option = "";
|
if (!hasCity && city_name == old_city) {
|
hasCity = true;
|
}
|
if (date_type == "Name") {
|
option = "<option value = '" + city_name + "'>" + city_name + "</option>";
|
} else {
|
option = "<option value = '" + city_keyid + "'>" + city_name + "</option>";
|
}
|
$(option).appendTo($("#selectCity"));
|
$("#selectProvince").attr("class", "fl");
|
|
var classStr = $("#selectCity").attr("class");
|
$("#selectCity").attr("class", "");
|
$("#selectCity").attr("class", classStr);
|
|
$("#selectCounty").attr("class", "fl ml5px");
|
}
|
}
|
if (hasCity) {
|
$("#selectCity").val(old_city);
|
}
|
$("#selectCity").change();
|
$("#selectCity").attr('isLoaded', true);
|
}
|
});
|
});
|
//加载区县
|
$("#selectCity").live("change", function () {
|
if (window.citychangecallback && $("#selectCity").attr('isLoaded') == 'true') window.citychangecallback();
|
$.ajax({
|
url: "/Pages/common/CommonAjax.aspx",
|
type: "POST",
|
dataType: "html",
|
data: { old_city: $("#selectCity").val(), cityType: "county", date_type: date_type },
|
global: false,
|
cache: false,
|
success: function (data) {
|
$("#selectCounty").html("<option value=''>请选择</option>");
|
var myobj = null;
|
if (data != null && data != "" && data != undefined) {
|
myobj = eval('(' + data + ')');
|
}
|
var hasCounty = false;
|
if (myobj != null && myobj.length > 0) {
|
for (var i = 0; i < myobj.length; i++) {
|
var city_keyid = myobj[i].Keyid;
|
var city_name = myobj[i].Name;
|
var option = "";
|
if (!hasCounty && city_name == old_county) {
|
hasCounty = true;
|
}
|
if (date_type == "Name") {
|
option = "<option value = '" + city_name + "'>" + city_name + "</option>";
|
} else {
|
option = "<option value = '" + city_keyid + "'>" + city_name + "</option>";
|
}
|
$(option).appendTo($("#selectCounty"));
|
$("#selectProvince").attr("class", "fl");
|
|
var classStr = $("#selectCity").attr("class");
|
$("#selectCity").attr("class", "");
|
$("#selectCity").attr("class", classStr);
|
|
$("#selectCounty").attr("class", "fl ml5px");
|
}
|
if (hasCounty) {
|
$("#selectCounty").val(old_county);
|
}
|
//$("#selectCounty").change();
|
$("#selectCounty").attr('isLoaded', true);
|
}
|
}
|
});
|
});
|
$("#selectCounty").live("change", function () {
|
if (window.citychangecallback && $("#selectCounty").attr('isLoaded') == 'true') window.citychangecallback();
|
});
|
} catch (e) {
|
|
}
|
|
}
|
|
function GetProvince(date_type) {
|
if (date_type == "Name") {
|
return $("#selectProvince").find("option:selected").text();
|
} else {
|
return $("#selectProvince").val();
|
}
|
}
|
|
function GetCity(date_type) {
|
if (date_type == "Name") {
|
return $("#selectCity").find("option:selected").text();
|
} else {
|
return $("#selectCity").val();
|
}
|
}
|
|
function GetCounty(date_type) {
|
if (date_type == "Name") {
|
return $("#selectCounty").find("option:selected").text();
|
} else {
|
return $("#selectCounty").val();
|
}
|
}
|