JQuery TR在AJAX重新加载时未被删除

时间:2016-12-26 21:11:54

标签: jquery

synchChecks()函数无法删除表行,但是对TR的JQuery选择器引用似乎是正确的。什么可能导致这个?我正在应用AJAX重新加载的逻辑,正如预期的那样,选中的TR被检查,但点击失败并且没有抛出任何错误。

    $(function () {

        $(".pagination li").css("cursor","pointer")
        $('.pagination').on('click', 'li', function () {
            $('.pagination li').removeClass("active");
            $(this).addClass("active");
        });


        $('#myPager').on('click', 'a', function () {
            $.ajax({
                url: this.href,
                type: 'GET',
                cache: false,
                success: function (result) {
                    $('#divVendors').html(result);
                    applyVendorLogic();
                    synchChecks();
                }
            });
            return false;
        });
    });

    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////

    function applyVendorLogic() {
        $("#tblVendorSelect").on('click', '.chkVendor', function () {

            if ($(this).prop("checked") == true) {

                var $trid = "xtr" + $(this).parent().parent().prop("id");
                var $tr = $(this).parent().parent();
                var $ts = $tr.clone();
                $ts.attr("id", $trid);

                $ts.on('click', '.chkVendor', function () {
                    $("#vendorSelection #" + $ts.attr("id")).remove();
                })

                $tr.on('click', '.chkVendor', function () {
                    if ($(this).prop("checked") == false) {
                        $("#vendorSelection #" + $ts.attr("id")).remove();
                    }
                })

                $("#vendorSelection").append($ts);

            }

        });
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////

    function synchChecks() {

        $("#vendorSelection .chkVendor").each(function () {
            if ($(this).prop("checked") == true) {
                $("#tblVendorSelect #" + $(this).attr("id")).prop("checked", true);
                $("#tblVendorSelect").on('click',"#" + $(this).attr("id"),function () {

                    if ($(this).prop("checked") == false) {
                        $("#vendorSelection #x" + $(this).parent().parent().attr("id")).remove();
                    }
                })
            }
        });

    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////

appplyVendorLogic synchChecks

现在我成功地在页面之间导航并保持同步。如果选中一个框,则另一个框也是如此。如果未选中,则删除该行,并且也取消选中选择表中的复选框。

0 个答案:

没有答案