我是javascript的新手,我正在尝试合并2个javascript块,但我正在分崩离析?
第一块
<script>
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('table.table tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="'+title+' ARA" />' );
} );
// DataTable
var table = $('table.table').DataTable();
// Apply the search
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
} );
</script>
第二块
$('table.table').DataTable({
"order": [
[0, "desc"]
],
paging: true,
"oLanguage": {
"sUrl": "js/dil/LANGUAGE.json",
}
} );
我想添加&#34; oLanguage&#34;和&#34;命令&#34;第一个javascript的行。我该怎么办?
答案 0 :(得分:2)
只需将数组从DataTables
复制粘贴到第一部分:
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('table.table tfoot th').each(function () {
$(this).html('<input type="text" placeholder="'+$(this).text()+' ARA" />');
});
// DataTable
var table = $('table.table').DataTable({
order: [
[0, "desc"]
],
paging: true,
oLanguage: {
sUrl: "js/dil/LANGUAGE.json",
}
});
// Apply the search
table.columns().every(function () {
var that = this;
$('input', this.footer()).on('keyup change', function () {
if (that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
});
});
});
注意 DataTable曾经在hUngarianNotation中拥有它的变量,后来又转移到了camlCase,因此新API无法识别您的oLanguage