簡體   English   中英

腳本標記不會關閉

[英]Script Tag doesn't close

我正在一個包含Table插件的網站上工作。 插件get由<script>標簽導入並使用javascript執行。 除了我使用Bootstrap,所以bootstrap.min.js文件也是importet。 以下是它的外觀:

         <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

         <!-- Include all compiled plugins (below), or include individual files as needed -->
         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

         <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>

         <script type="text/javascript">
               $(document).ready( function () {
                        $('#table_id').DataTable();
               } );
          </script>

所有這些代碼都在關閉<body>標記之前放置。 如果我在我的網站空間上傳文件並訪問該頁面,則不會執行任何腳本。 如果我查看Chrome中的源代碼,我看到的是<script>標記未正確關閉:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"/>
        <script charset="utf8" src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.js" type="text/javascript"/>
        <script type="text/javascript">
            $(document).ready( function () {
                    $('#table_id').DataTable();
            } );    
    </script>

我已經嘗試將腳本放在代碼中的不同位置,但每次都有同樣的問題。 我也試過這個答案,但評論甚至沒有顯示在源代碼中。

有沒有正確的方法來解決這個問題?

(更新:完整代碼):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  exclude-result-prefixes="xsl">
<xsl:template match="/">
<html>
    <head>
        <title>Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

        <!-- Latest compiled and minified Bootstrap CSS -->
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

        <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.15/css/jquery.dataTables.css"/>



    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-lg-12">

                    <table id="table_id" class="display">
                            <thead>
                                <tr>
                                    <th>Column 1</th>
                                    <th>Column 2</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>Row 1 Data 1</td>
                                    <td>Row 1 Data 2</td>
                                </tr>
                                <tr>
                                    <td>Row 2 Data 1</td>
                                    <td>Row 2 Data 2</td>
                                </tr>
                            </tbody>
                    </table>

                </div>
            </div>
        </div>
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
         <!-- Include all compiled plugins (below), or include individual files as needed -->
         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

         <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>

        <script type="text/javascript">
            $(document).ready( function () {
                    $('#table_id').DataTable();
            } );
        </script>
    </body>
</html>

// You are not closing scripts tag

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"/></script>
        <script charset="utf8" src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.js" type="text/javascript"/></script>
        <script type="text/javascript">
            $(document).ready( function () {
                    $('#table_id').DataTable();
            } );   
</script>

我沒有在這里看到任何問題,但為什么不嘗試自動關閉腳本標記來加載jQuery。

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" />
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"/>
<script charset="utf8" src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.js" type="text/javascript"/>
        <script type="text/javascript">
            $(document).ready( function () {
                    $('#table_id').DataTable();
            });    
    </script>

你使用的是錯誤的字符集。 它是utf-8 ,而不是utf8

https://www.w3.org/International/questions/qa-html-encoding-declarations

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM