$(document).ready(function () {
var anOpen = [];
var oTable = $('#table_id').dataTable();
$('#table_id tbody').on('click', 'tr', function (e) {
var nTr = this.parentNode;
var i = $.inArray(nTr, anOpen);
console.log("clicked|" + i);
if (i == -1) {
var nDetailsRow = oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push(nTr);
console.log("open");
}
else {
oTable.fnClose( nTr );
anOpen.splice( i, 1 );
console.log("closed");
}
});
function fnFormatDetails(oTable, nTr) {
var oData = oTable.fnGetData(nTr);
var sOut =
'<div class="innerDetails">' +
'<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
'<tr><td>Rendering engine:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Browser:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Platform:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Version:</td><td>' + 'hi' + '</td></tr>' +
'<tr><td>Grade:</td><td>' + 'hi' + '</td></tr>' +
'</table>' +
'</div>';
return sOut;
}
只是给出了它的一部分,当我单击该行时,它确实触发了 if (i==-1),然后当我再次单击它时,它触发了 else 并来回工作,问题是我无法显示任何内容. 桌子就坐了,新的在它下面打开了另一个桌子,就像它应该的那样。控制台中没有错误,只有正确的控制台日志。