如何将级联函数绑定到 DOM 中尚未包含的元素:
(function ($) {
$.fn.cascade = function (options) {
var defaults = {};
var opts = $.extend(defaults, options);
// REST OF THE CODE NOT IMPORTANT FOR THE QUESTION //
};
})(jQuery);
将被加载的 Partialview 将具有:
@Html.DisplayNameFor(m => m.PTDistrict_Id)
@Html.DropDownListFor(m => m.PTDistrict_Id, Model.PTDistrictList, HeelpResources.PTDistrictViewDropDownListFirstRecord, new { id = "districtDropdown" })
@Html.ValidationMessageFor(m => m.PTDistrict_Id)
我试过这个但没有运气:
$(document).on("change", "#districtDropdown", function () {
$.cascade({
url: "/Address/ListCouncilByDistrict",
paramName: "districtId",
firstOption: 'Selecione o Concelho...',
childSelect: $("#councilDropdown")
});
});
有任何想法吗?谢谢。