如何使用Jade/Pug渲染内联JavaScript? [英] How can I render inline JavaScript with Jade / Pug?
本文介绍了如何使用Jade/Pug渲染内联JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Jade(http://jade-lang.com/)使JavaScript呈现在页面上
I'm trying to get JavaScript to render on my page using Jade (http://jade-lang.com/)
我的项目在带有Express的NodeJS中,在我想在头中编写一些内联JavaScript之前,所有传送都正常工作.即使从Jade文档中获取示例,我也无法使它发挥作用,我想念的是什么?
My project is in NodeJS with Express, eveything is working correctly until I want to write some inline JavaScript in the head. Even taking the examples from the Jade docs I can't get it to work what am I missing?
!!! 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>
这里肯定有任何想念的东西吗?
Somethings definitely a miss here any ideas?
推荐答案
只需在后面加上一个点的'script'标记即可.
simply use a 'script' tag with a dot after.
script.
var users = !{JSON.stringify(users).replace(/<\//g, "<\\/")}
https://github.com/pugjs/pug/blob/master/examples/dynamicscript.pug
这篇关于如何使用Jade/Pug渲染内联JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文