Javascript:选择页面上的所有复选框.它会检查所有内容一秒钟,然后消失

Javascript: selecting all checkboxes on a page. It checks all for a second and then disappears

本文关键字:检查 一秒钟 消失 然后 复选框 选择 Javascript      更新时间:2023-09-26

我有一个呈现部分视图的视图。Index.cshtml 包含一个分部视图。

下面的div 存在于部分视图中

            <div id="sa-da">
                <input type="checkbox" id="selectAll"/><span>@T("Select / Deselect all invoices")</span> 
                <div class="payinvoices"><input class="amebtn" id="PayInvoices" type="button" text="Pay Invoices"  onclick="RemovePagination();"/> </div>
            </div>

我正在使用下面的方法通过单击按钮在部分视图中关闭网格(网络网格)上的分页

            function RemovePagination()
                 {      
                    UpdateGrid("","clkPayInv");
                    $('#invoicestatus').val('unpaid');            
                    SelectAllCheckboxesOnLoad();
                 }

我希望下面的功能在单击按钮时也选中所有复选框

             function SelectAllCheckboxesOnLoad()
             {
                var aa= document.getElementsByTagName("input");
                for (var i =0; i < aa.length; i++){
                    if (aa[i].type == 'checkbox')
                        aa[i].checked = true;
                }
             }

??单击按钮时会选中复选框,但不会保持选中状态。它只是闪烁一秒钟,显示选中的所有框,然后消失。我该如何解决这个问题?

            function UpdateGrid(searchString,whatWasClicked) {
                    $jq.ajax({
                        url: '@Url.Action("Invoices")',
                        type: "GET",
                        cache: false,  
                        data: { status: $("#invoicestatus").val(), from: $("#from").val(), thru: $("#to").val(), search: searchString, payInvClickBtn:whatWasClicked},
                        dataType: "html",
                        global: false,
                        error: function (jqXHR, status, error) { if (jqXHR.status == 401) { window.location.replace(location.href); } } ,
                        success: function (result, status, hr) {
                            $('#Grid').html(result);
                        }
                    });
                }

出现此问题的原因是,触发检查/取消检查时 ajax 调用未完成。将呼叫下至

SelectAllCheckboxesOnLoad();

在成功方法中,之后

$('#Grid').html(result);