Javascript:Uncaught SyntaxError:意外的令牌<

时间:2016-06-21 15:09:05

标签: javascript jquery datatables

我有一个名为table_java.js的js文件,我试图让它在我的HTML文件test.html中运行。 我一直收到错误,Uncaught SyntaxError: Unexpected token <我认为问题是js文件被读作文本文件。但我不确定这是不是问题/不知道如何修复它。任何帮助/建议将不胜感激。

这是table_java.js

<script type ="text/javascript">
<!--
        $(document).ready( function () {

                // Setup - add a text input to each footer cell
                $('#POGs_table tfoot th').each( function () {
                    var title = $(this).text();
                    $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
                } );

            var table = $('#POGs_table').DataTable( {
                "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                "order": [[0,"asc"]],
                "aoColumnDefs": [ { "sSortDataType": "numeric", "aTargets": [3,4,5] } ]
            } );


                // 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();
                            }
                    });
                });
            //Hide/Show function
            $('a.showHideColumn').on('click', function() {

                var tableColumn = table.column($(this).attr('data-columnindex'));
                tableColumn.visible(!tableColumn.visible());
            });
        });
-->
</script>

以下是test.html的主要部分

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Phage Orthologous Groups</title>
    <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="krist_datatables.css">
    <link rel="stylesheet" type="text/css" href="table_try.css">
    <script type="text/javascript" charset="utf8" src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
    <script type="text/javascript" src="http://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
    <script  type="text/javascript" src="table_java.js"></script>
</head>

2 个答案:

答案 0 :(得分:0)

从table_java.js中删除标签,它已经是JS脚本

答案 1 :(得分:0)

-->无效的javascript。必须对其进行转义://-->

这些天你不需要脚本块中的html注释。任何仍然使用如此古老而不支持<script>的浏览器的人都是恐龙,你不需要担心支持。