【问题标题】:Jade template failed to render javascript correctlyJade 模板无法正确呈现 javascript
【发布时间】:2015-03-20 16:29:00
【问题描述】:

我有一个关于从块中包含脚本的问题

来自 express-generator,

layout.jade

doctype html
html
    head
        title= title
        link(rel='stylesheet', href='/stylesheets/style.css')
    body
        block content
        include sidebar
    script(src='/javascripts/jquery.js')
    block bottomscripts

sidebar.jade

block bottomscripts
    script(src='/javascripts/sidebar.js')

输出

<html>
    <head>
        <title>Express</title>
        <link rel="stylesheet" href="/stylesheets/style.css">
      </head>
      <body>
        <h1>Express</h1>
        <p>Welcome to Express</p>
        <script src="/javascripts/sidebar.js">
        </script><script src="/javascripts/jquery.js"></script>
      </body>
</html>

如何将 sidebar.js 移动到 jquery.js 下方?我需要在 sidebar.jade 内完成此操作

谢谢

【问题讨论】:

    标签: node.js templates express pug


    【解决方案1】:

    您是否尝试过在您的代码块中包含 jquery.js?似乎它们都是“底稿”。

    block bottomscripts
        script(src='/javascripts/jquery.js')
        script(src='/javascripts/sidebar.js')
    

    【讨论】:

      【解决方案2】:

      所以可以移动你的 include 语句并将你的 jquery stipt 语句的缩进更改为

      doctype html
      html
          head
              title= title
              link(rel='stylesheet', href='/stylesheets/style.css')
          body
              block content        
              script(src='/javascripts/jquery.js')
              include sidebar
          block bottomscripts
      

      得到

      <!DOCTYPE html>
      <html>
      
      <head>
        <title></title>
        <link rel="stylesheet" href="/stylesheets/style.css">
      </head>
      
      <body>
        <script src="/javascripts/jquery.js"></script>
        <script src="/javascripts/sidebar.js"></script>
      </body>
      
      </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-05
        • 1970-01-01
        • 2017-06-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多