如何在网页中组合javascript(s)?

时间:2015-06-08 20:52:54

标签: javascript datatables

我的网站包含以下内容:

 ...

 <script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
 <script src="//cdn.datatables.net/responsive/1.0.6/js/dataTables.responsive.js"></script>

我需要将这些脚本合并为一个:

 <script>$(document).ready(function() {$('#cccr').DataTable( { "order": [[ 0, "desc" ], [2,"asc"], [1,"asc"]], "aaSorting": [], "bPaginate": false, "bLengthChange": true, "bFilter": true, "bSort": true, "bInfo": true, "sPaginationType": "full_numbers", "sScrollY": "25rem",  "bStateSave": false, "autoWidth": true });} );</script>

 <script>$(document).ready(function() {var oTable = $('#cccr').dataTable();oTable.fnFilter( 'parry' );} );</script>

 <script>$(document).ready(function() {new $.fn.dataTable.Responsive( table );} );</script>

问题是我希望页面能够响应并且让响应式js调用代码分开来解决所有问题。我怎样才能安全地组合这些线? (最好不要“$(文件).ready”。

1 个答案:

答案 0 :(得分:0)

像这样

<script>   
$(document).ready(function() {
  $('#cccr').DataTable({
    "order": [
        [0, "desc"],
        [2, "asc"],
        [1, "asc"]
    ],
    "aaSorting": [],
    "bPaginate": false,
    "bLengthChange": true,
    "bFilter": true,
    "bSort": true,
    "bInfo": true,
    "sPaginationType": "full_numbers",
    "sScrollY": "25rem",
    "bStateSave": false,
    "autoWidth": true
});
 var oTable = $('#cccr').dataTable();
            oTable.fnFilter('parry');
  new $.fn.dataTable.Responsive(table);
 });
 </script>