本文介绍了如何使用 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/)
我的项目在 NodeJS 和 Express 中,一切正常,直到我想在头中编写一些内联 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!