0

我有一个 jquery 对话框,在其中我加载了两个部分视图,一个简单的主/详细信息,当我在保存详细信息后返回主视图时,单击按钮没有响应。

我发布了一些代码:

掌握

        $('#dialogActivities').dialog({
        autoOpen: false,
        open: function (event, ui) {
            var id = $(this).data('id');
            var urlList = '@Url.Action("ActivityList", "Contacts")';

            $(this).load(urlList, function ()
            {
                $(".k-grid-ActivityEdit").bind("click", function ()
                {
                    var grid = $("#gridYear").data("kendoGrid");
                    var selectedData = grid.dataItem(grid.select());
                    if (selectedData)
                    {
                        var urlEdit = '@Url.Action("ActivityEdit", "Contacts")';
                        $('#dialogActivities').dialog().load(urlEdit);
                    }
                });
            });
        }
    });

细节

$(document).on('submit', '#frmActivityEdit', function ()
{
    $.ajax({
        cache: false,
        url: this.action,
        type: this.method,
        data: $(this).serialize(),
        success: function (result)
        {
            if (result.success)
            {
                var model = @Html.Raw(Json.Encode(Model));
                var urlList = '@Url.Action("ActivityList", "Contacts")';

                $('#dialogActivities').dialog().load(urlList);
            }
        }
    });
    return false;
});
4

1 回答 1

0

请尝试替换这段代码:

$(".k-grid-ActivityEdit").bind("click", function ()
            {
                var grid = $("#gridYear").data("kendoGrid");
                var selectedData = grid.dataItem(grid.select());
                if (selectedData)
                {
                    var urlEdit = '@Url.Action("ActivityEdit", "Contacts")';
                    $('#dialogActivities').dialog().load(urlEdit);
                }
            });

有了这个:

$(document).on("click", ".k-grid-ActivityEdit", function ()
            {
                var grid = $("#gridYear").data("kendoGrid");
                var selectedData = grid.dataItem(grid.select());
                if (selectedData)
                {
                    var urlEdit = '@Url.Action("ActivityEdit", "Contacts")';
                    $('#dialogActivities').dialog().load(urlEdit);
                }
            });

不同之处在于,使用 on 函数进行绑定也适用于动态添加的元素。它可以解决您的问题。

于 2013-10-03T10:32:34.950 回答