我如何使用Jade渲染内联JavaScript?
我试图让JavaScript在我的页面上使用Jade(http://jade-lang.com/)呈现
我的项目是在ExpressJet的NodeJS中,eveything正常工作,直到我想在头部写入一些内联JavaScript。 即使从Jade文档中拿出例子,我也无法让它发挥作用,我错过了什么?
玉模板
!!! 5
html(lang="en")
  head
    title "Test"
    script(type='text/javascript')
      if (10 == 10) {
        alert("working")
      }
  body
在浏览器中生成呈现的HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <title>"Test"</title>
  <script type="text/javascript">
    <if>(10 == 10) {<alert working></alert></if>}
  </script>
</head>
<body>
</body>
</html>
有些事情肯定会在这里错过任何想法?
简单地使用带有点的'脚本'标签。
script.
  var users = !{JSON.stringify(users).replace(/<//g, "</")}
https://github.com/pugjs/pug/blob/master/examples/dynamicscript.pug
  :javascript版本7.0中删除了:javascript过滤器 
  文档说你现在应该使用script标签,然后是.  字符和前面的空间。 
例:
script.
  if (usingJade)
    console.log('you are awesome')
  else
    console.log('use jade')
将被编译为
<script>
  if (usingJade)
    console.log('you are awesome')
  else
    console.log('use jade')
</script>
使用指定类型的脚本标记,只需将它包含在点之前即可:
script(type="text/javascript").
  if (10 == 10) {
    alert("working");
  }
这将编译为:
<script type="text/javascript">
  if (10 == 10) {
    alert("working");
  }
</script>
想对梁山的回答发表评论,但没有足够的声望。 希望这可以帮助
链接地址: http://www.djcxy.com/p/88895.html