function CascadeDropDowns(parentClass, childClass, action, callback) {
var DropDownId = $(parentClass + " option:selected").val();
$.ajax({
url: "/site/" + action,
data: { DropDownId: DropDownId },
dataType: "json",
type: "POST",
error: function () {
alert("An error occurred.");
},
success: function (data) {
var items = "";
$.each(data, function (i, item) {
items += "<option value=\"" + item.Value + "\">" + item.Text + "</option>";
});
$(childClass).html(items);
$(childClass)[0].selectedIndex = 0;
callback();
}
});
}
$(document).ready(function () {
// Populates all child drop downs on load
var callback = function () {
CascadeDropDowns(".ConfigGroupDDL", ".ConfigNameDDL", "GetParameters");
};
CascadeDropDowns(".DeviceTypeDDL", ".ConfigGroupDDL", "GetGroups", callback);
// Populates all child drop downs parent change
$(".DeviceTypeDDL").change(function () {
var callback = function () {
CascadeDropDowns(".ConfigGroupDDL", ".ConfigNameDDL", "GetParameters");
};
CascadeDropDowns(".DeviceTypeDDL", ".ConfigGroupDDL", "GetGroups", callback);
});
$(".ConfigGroupDDL").change(function () {
CascadeDropDowns(".ConfigGroupDDL", ".ConfigNameDDL", "GetParameters");
});
});
这运行良好并以正确的顺序级联下拉菜单,但 Firefox 调试器显示错误,即引发警报并询问 Id 是否可以调试。
任何建议都会很棒