簡體   English   中英

數據表未捕獲類型錯誤

[英]Datatables Uncaught Type Error

我有Datatables和GridRowCount()來獲取html表中指定組的行數,jfiddle站點在這里 當我運行代碼時,Chrome瀏覽器拋出未捕獲的類型錯誤(...)。live不是函數。


顯示來自控制台的錯誤。

 rowtoggle.js:30 Uncaught TypeError: $(...).live is not a function rowtoggle.js:30 Uncaught TypeError: $(...).live is not a functionGridRowCount @ rowtoggle.js:30(anonymous function) @ rowtoggle.js:16i @ jquery-1.12.2.min.js:2j.fireWith @ jquery-1.12.2.min.js:2n.extend.ready @ jquery-1.12.2.min.js:2K @ jquery-1.12.2.min.js:2 Navigated to http://localhost/datacentre/admin/request_pending.php rowtoggle.js:30 Uncaught TypeError: $(...).live is not a functionGridRowCount @ rowtoggle.js:30(anonymous function) @ rowtoggle.js:16i @ jquery-1.12.2.min.js:2j.fireWith @ jquery-1.12.2.min.js:2n.extend.ready @ jquery-1.12.2.min.js:2K @ jquery-1.12.2.min.js:2 Navigated to http://localhost/datacentre/admin/request_pending.php 


下面是Datatables和GroupRowCount()插件的代碼。

 $( document ).ready(function() { $('#example').dataTable({ "bLengthChange": false, "bPaginate": false, "bJQueryUI": true }).rowGrouping({ iGroupingColumnIndex: 1, sGroupingColumnSortDirection: "asc", iGroupingOrderByColumnIndex: 0 , bExpandableGrouping: true, bExpandSingleGroup: false, iExpandGroupOffset: -1, asExpandedGroups: [""] }); GridRowCount(); }); function GridRowCount() { $('span.rowCount-grid').remove(); $('input.expandedOrCollapsedGroup').remove(); $('.dataTables_wrapper').find('[id|=group-id]').each(function () { var rowCount = $(this).nextUntil('[id|=group-id]').length; $(this).find('td').append($('<span />', { 'class': 'rowCount-grid' }).append($('<b />', { 'text': rowCount }))); }); $('.dataTables_wrapper').find('.dataTables_filter').append($('<input />', { 'type': 'button', 'class': 'expandedOrCollapsedGroup collapsed', 'value': 'Expanded All Group' })); **$('.expandedOrCollapsedGroup').live('click', function () { if ($(this).hasClass('collapsed')) {** $(this).addClass('expanded').removeClass('collapsed').val('Collapse All Group').parents('.dataTables_wrapper').find('.collapsed-group').trigger('click'); } else { $(this).addClass('collapsed').removeClass('expanded').val('Expanded All Group').parents('.dataTables_wrapper').find('.expanded-group').trigger('click'); } }); }; 

.live()在jQuery 1.7中已棄用,在1.9版中已刪除。 您應該使用.on()

$('.expandedOrCollapsedGroup').on('click', function () {
//Your code
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM