我想在我的initComplete函数中触发if语句,但它不起作用。为什么是这样? 这是我的代码:数据表初始化完成回调没有触发
var dataTable = $('.datatable-column-search-inputs').DataTable({
initComplete: function() {
var myDate = new Date();
var n = myDate.getHours();
if (n < 12) {
dataTable.fnFilter(this.value, 'DESAYUNOS');
alert("LOGRO DESAYUNOS");
}
else /* 12:00pm-5:59pm */
if (n >= 12 && n <= 17) {
dataTable.fnFilter(this.value, 'COMIDAS');
alert("LOGRO COMIDAS");
}
else /* 6:00PM-12:00AM*/
if (n > 17 && n <= 24) {
$('#sel2').change(function() {
dataTable.fnFilter(this.value, 'CENAS');
alert("LOGRO CENAS");
});
}
else /* the hour is not between 0 and 24, so something is wrong */ {
alert("I'm not sure what time it is!");
}
});
}
});
HTML表:
<table class='table datatable-column-search-inputs table-hover table-striped table-bordered'>
<thead>
<tr>
<td class='thead_search'>Platillo</td>
<td class='thead_select'>Pdv</td>
<td class='thead_select'>Rid</td>
<td>PV</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>Total</td>
<td class='text-center'>Venta</td>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="4" style="text-align:left">Total:</th>
<th></th>
</tr>
</tfoot>
</table>
我只是说表的HTML sintax,该表由填充一个ajax调用,它填充正确,但我的IF语句在initComplet e:从不发送警报,不管是什么时候都不是最后的其他人 为什么不触发回调函数?
你可以添加包含表格的html部分吗? – gen
你刚刚添加了表格代码,所有if,它们中的更多者发送警报,这意味着更接近他们@NisseEngström –
只是一个猜测,但是你可以添加一个id到你的表并初始化id上的数据表? – gen