2017-06-16 54 views
-3

我是新的JavaScript和我想结合2个JavaScript块,但我分崩离析?如何结合两个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", 
} 
}); 

我想补充 “oLanguage” 和 “秩序” 行第一个JavaScript。我该怎么办?

回答

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(); 
      } 
     }); 
    }); 
}); 

说明曾经有过它在匈牙利命名法,后来搬到camlCase变量数据表,所以它是最有可能你的oLanguage是没有被新的API识别

+0

+ $(this).text()+不显示seacrh结果?其他人正在工作 – Andrew