联动的页面
<script src="js/jquery-1.9.1.min.js"></script>
<script>
$(function () {
$.get("ProviceHandler.ashx", function (result) {
//alert(result);
//console.log(result);
var sub = "";
var jsonarry = JSON.parse(result);
for (var i = 0; i < jsonarry.length; i++) {
sub += "<option value=" + jsonarry[i].Id + ">" + jsonarry[i].Name + "</option>";
}
$("#provace").html(sub);
});
//给下拉列表注册改变事件
$("#provace").change(function () {
//获取id
//alert($("#provace").val());
//获取文本
// alert($("#provace").find("option:selected").html());
//通过省id去查询数据库
$.get("CityHandler.ashx", { proviceId: $("#provace").val() }, function (result) {
console.log(result);
//需要把json转化成字符串
var sub = "";
var jsonarry = JSON.parse(result);
for (var i = 0; i < jsonarry.length; i++) {
sub += "<option value=" + jsonarry[i].Id + ">" + jsonarry[i].Name + "</option>";
}
$("#Select1").html(sub);
});
//
$("#Select1").change(function () {
$.get("XuanHandler.ashx", { CityId: $("#Select1").val() }, function (result) {
console.log(result);
//需要把json转化成字符串
var sub = "";
var jsonarry = JSON.parse(result);
for (var i = 0; i < jsonarry.length; i++) {
sub += "<option value=" + jsonarry[i].Id + ">" + jsonarry[i].Name + "</option>";
}
$("#Select2").html(sub);
});
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
省:<select id="provace">
</select>
市:<select id="Select1">
</select>
县:<select id="Select2">
</select>
</div>
</form>
</body>