无刷新省市县三级联动(AJAX/Webservice)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var txtprov;
var txtcity;
$('#ddlsheng').append("<option value='0'>--- 请选择 ---</option>");
$('#ddlshi').append("<option value='0'>--- 请选择 ---</option>");
$('#ddlxian').append("<option value='0'>--- 请选择 ---</option>");
//省
function aa() {
三联动.WebService1.sanji(onSuccess1, onFailed1);
}
aa();
function onSuccess1(result) {
for (var i = 0; i < result.length; i++) {
var provinceID = result[i].split('-')[0].toString();
var province = result[i].split('-')[1].toString();
$('#ddlsheng').append("<option value='" + provinceID + "'>" + province + "</option>");
}
}
$('#ddlsheng').change(function () {
$('#ddlshi option:not(eq(1))').remove();
$('#ddlxian option:not(eq(1))').remove();
$('#ddlxian').append("<option value='0'>--- 请选择 ---</option>");
txtprov = $('#ddlsheng option:selected').val();
bb();
})
function onFailed1() {
alert('获取失败!');
}
//市
function bb() {
三联动.WebService1.city(txtprov, onSuccess2, onFailed2);
}
function onSuccess2(result2) {
for (var i = 0; i < result2.length; i++) {
var cityID = result2[i].split('-')[0].toString();
var city = result2[i].split('-')[1].toString();
$('#ddlshi').append("<option value='" + cityID + "'>" + city + "</option>");
}
}
$('#ddlshi').change(function () {
$('#ddlxian option:not(eq(1))').remove();
txtcity = $('#ddlshi option:selected').val();
cc();
})
function onFailed2() {
alert('获取失败!');
}
//县
function cc() {
三联动.WebService1.area(txtcity, onSuccess3, onFailed3);
}
function onSuccess3(result3) {
for (var i = 0; i < result3.length; i++) {
var areaID = result3[i].split('-')[0].toString();
var area = result3[i].split('-')[1].toString();
$('#ddlxian').append("<option value='" + areaID + "'>" + area + "</option>");
}
}
function onFailed3() {
alert('获取失败!');
}
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="mydiv"></div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebService1.asmx" />
</Services>
</asp:ScriptManager>
<div>
省<asp:DropDownList ID="ddlsheng" runat="server">
</asp:DropDownList>
市<asp:DropDownList ID="ddlshi" runat="server">
</asp:DropDownList>
县<asp:DropDownList ID="ddlxian" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
</html>