本文应用到jquery、json、asp.net结合来实现无刷新三级联动效果,使用asp.net实现二级联动、三级联动效果很简单,不过不是无刷新就不爽了,所以收集一个无刷新联动的实现例子。
三个下拉控件:
<asp:DropDownList ID="ddl1" runat="server" Width="100px" ></asp:DropDownList>
<asp:DropDownList ID="ddl2" runat="server" Width="100px" ></asp:DropDownList>
<asp:DropDownList ID="ddl3" runat="server" Width="100px" ></asp:DropDownList>
JS代码:
Code
<script src="js/jquery-1.4.2.min.js" type="text/javascript" ></script>
<script type="text/javascript">
$(document).ready(function () {
GetA();
$("#ddl1").change(function () { GetB(); });
$("#ddl2").change(function () { GetC(); });
});
function GetA()
{
$("#ddl1").html("");
$("#ddl1").append("<option value=''-1'' selected=''selected''>请选择...</option>");
//$("select[name$=ddl1] > option:selected").remove();
var strId = 0;
$.getJSON("LoadClass.ashx?ddlId=" strId, function (data) {
for (var i = 0; i < data.length; i ) {
$("select[name$=ddl1]").append($("<option></option>").val(data[i].ID).html(data[i].Cname));
};
GetB();
});
}
function GetB()
{
$("#ddl2").html(""); $("#ddl3").html("");
var strId = $("#ddl1").attr("value");
if (strId != 0) {
$.getJSON("LoadClass.ashx?ddlId=" strId, function (data) {
for (var i = 0; i < data.length; i ) {
$("select[name$=ddl2]").append($("<option></option>").val(data[i].ID).html(data[i].Cname));
};
GetC();
});
}
}
function GetC()
{
$("#ddl3").html("");
var strId = $("#ddl2").attr("value");
if (strId != 0) {
$.getJSON("LoadClass.ashx?ddlId=" strId, function (data) {
for (var i = 0; i < data.length; i ) {
$("select[name$=ddl3]").append($("<option></option>").val(data[i].ID).html(data[i].Cname));
};
});
}
}
</script>
|