本文介绍了如何使用Jade渲染内置JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Jade(http://jade-lang.com/)在我的页面上使用JavaScript渲染
我的项目在NodeJS中, Express,eveything正常工作,直到我想写一些内置的JavaScript在头。甚至从翡翠文件中得到的例子我不能让它工作,我错过了什么?
玉模板
!!! 5
html(lang =en)
头
标题测试
脚本(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>
这里有什么想法吗?
脚本。
/ pre>
var users =!{JSON.stringify(users).replace(/< \ // g,< \\ /)}
I'm trying to get JavaScript to render on my page using Jade (http://jade-lang.com/)
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?
Jade template
!!! 5 html(lang="en") head title "Test" script(type='text/javascript') if (10 == 10) { alert("working") } body
Resulting rendered HTML in browser
<!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?
解决方案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渲染内置JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!