bootstrap table 生成的表格里動態添加HTML元素按鈕,JS中添加點擊事件,點擊沒反應---解決辦法


 bootstraptable中onExpandRow屬性---js  方法添加的 html代碼,然后給這代碼里面的 元素 添加 事件,卻獲取不該元素。(稱之為未來元素),由於是未來的 所以現在沒有這個元素,導致獲取不到。

//代碼不會觸發點擊事件;
//$("#btn_export_curr_page_detail").click(function () {
                //    var attribute = $('#btn_export_curr_page_detail').attr('data-attribute6');
                //    AjaxRequest_CreateExcelFromCurrPageDetail(attribute);
                //});

 

 onExpandRow: function (index, row, $detail) {
                    var cur_table = $detail.html('<table id="report-query-detaillist-table"></table>').find('table');
                    var html = "";
                    html += '<div id="detailToolbar" class="btn-group">';
                    html += '    <button id="btn_export_curr_page_detail" data-attribute6 = "' + row.ATTRIBUTE6 + '" type="button" class="btn btn-default export-curr-page-detail">';
                    html += '        <span class="glyphicon glyphicon-export" aria-hidden="true"></span>@Html.LocText("ExportCurrentPage", "導出本頁到Excel")';
                    html += '    </button>';
                    html += '    <input type="hidden" id="txt_TotalRecordCount_Detail" />';
                    html += '</div>';

 

$("#report-query-baselist-table").on("click", '#detailToolbar .export-curr-page-detail', function () {
                    var attribute = $(this).attr('data-attribute6');
                    AjaxRequest_CreateExcelFromCurrPageDetail(attribute);
                });

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM