【问题标题】:How to add javascript code, in html <head> tag using Slim, with id?如何在使用 Slim 的 html <head> 标签中添加 javascript 代码,并带有 id?
【发布时间】:2019-03-26 06:23:18
【问题描述】:

在下面Slim代码的sn-p中,我们如何在head标签中的javascript标签(类似html中的script标签)中添加id/type属性。

Slim docs 除了简单的警报语句之外,没有显示如何执行此操作。

附:为了简洁,代码保持简短

doctype html
html
  head
    title
      | Example
    <!-- How to add script id and type in the following code? -->
    javascript:
      alert('Slim supports embedded javascript!')
  body
    #root

【问题讨论】:

    标签: javascript html slim-lang


    【解决方案1】:

    根据你发的docs link,可以简单的内联脚本标签:

    doctype html
    html
      head
       title
         | Example
       <script id="ID_HERE">alert('Slim supports embedded javascript!')</script>
      body
        #root
    

    【讨论】:

    • 根据我的测试,我们需要一个管道来渲染 js 代码,&lt;script id="ID_HERE"&gt; | alert('Slim supports embedded javascript!')&lt;/script&gt;
    【解决方案2】:

    经过一些研究并从这里和那里挑选信息,我找到了上述答案的替代方案。

    doctype html
    html
      head
       title
         | Example
       script#ID_HERE type="text/javascript"
         | JS CODE
      body
        #root
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-28
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-05
      • 2014-05-23
      相关资源
      最近更新 更多