【问题标题】:class="init" meaning inside <script></script> declarationclass="init" 在 <script></script> 声明中的含义
【发布时间】:2014-11-18 16:58:17
【问题描述】:

我遇到了 Datatables jquery 插件的以下代码:

<script type="text/javascript" language="javascript" class="init">
        $(document).ready(function() {
            $('#example').dataTable();
        } );
</script>

class="init" 的目的是什么??

【问题讨论】:

标签: javascript jquery


【解决方案1】:

您可以像选择 DOM 中的任何其他标签一样选择 script 标签。目的?从代码块所在的 CSS“可视化”,到 JS/jQuery 动态代码生成。

【讨论】:

    【解决方案2】:

    它可以在某个地方使用,即从许多脚本 sn-ps 中动态选择一个以在其他地方使用。 像javascript模板语言

    <script class="say_hello english" type="text/x-handlebars-template">
        <p>Hello {{name}}</p>
    </script>
    <script class="say_hello german" type="text/x-handlebars-template">
       <p>Hallo {{name}}</p>
    </script>
    
    ...
    
    var say_hello_template = Handlebars.compile($('script.say_hello.' + language).html()); 
    $('#header').append(say_hello_template(user));
    

    希望对你有帮助

    【讨论】:

      【解决方案3】:

      在您使用&lt;script type="text/javascript" language="javascript" class="init" src="../../js/jFile.js"&gt;&lt;/script&gt; 等标签包含的javascript 文件中,可能包含引用类init 的编码。这种类型的类看起来像 CSS 编码,但它是对 javascript 的引用。

      在文本编辑器中打开 javascript 并搜索术语“init”。编码也可以定义为文章Is there a benefit to putting a class on a script tag?

      【讨论】:

        【解决方案4】:

        它只会使您的代码无效。

        class 不允许在 HTML4 和 XHTML 中的脚本中使用。

        虽然它在 HTML5 中有效,因为&lt;script&gt; 标签支持全局属性(包括class)。

        Check out the specification.

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-08-03
          • 2015-04-22
          • 1970-01-01
          • 2016-07-16
          • 1970-01-01
          • 2017-07-25
          • 1970-01-01
          • 2014-11-10
          相关资源
          最近更新 更多