我们可以在 EJS 中做类似 <% alert("TEMP") %> 的事情吗
CAN we do something like <% alert("TEMP") %> in EJS
我在 node.js 中从 res.render()
函数发送了一个变量,我必须在 EJS 模板中为我的脚本使用该变量以进行 DOM 操作。
来自Node.js:
res.render('index', {TEMP: 'xyz'});
在HTML中:
<p>This is a HTML demo</p>
<div>
I'm the TEMP variable: <%= TEMP %> <!-- this is going to output xyz -->
<script>
var getTemp = <%= TEMP %>;
console.log(getTemp);
</script>
</div>
我在 node.js 中从 res.render()
函数发送了一个变量,我必须在 EJS 模板中为我的脚本使用该变量以进行 DOM 操作。
来自Node.js:
res.render('index', {TEMP: 'xyz'});
在HTML中:
<p>This is a HTML demo</p>
<div>
I'm the TEMP variable: <%= TEMP %> <!-- this is going to output xyz -->
<script>
var getTemp = <%= TEMP %>;
console.log(getTemp);
</script>
</div>