在app.js文件中要求html标签的Id。

问题描述 投票:1回答:1

sort.ejs文件代码

<html>
<form action="/" method="post">
        <button type="submit" name="bubble" value="bubble">Bubble Sort</button>
</form>

<hr id = "123" style="height:<%=hgt%>px;border-left: <%=width%>px solid black;float: left;margin-left:<%=margin%>px">

</html>

app.js文件代码

app.get("/", function(req, res) {
    res.render("sort",{array:array,size:200,flag1:0,flag2:0,flag3:0,flag4:0});
});

app.post("/",function(req,res){


}

我想在post请求被触发时,在终端的sort.ejs文件中打印hr标签的样式元素(height, margin)的值。sort.ejs文件中使用的所有变量都是预定义的,我使用的是Node.js和EJS。我使用的是Node.js和EJS。

javascript html node.js ejs
1个回答
0
投票

我对你的查询有点困惑,但如果你问的是如何从app.js中获取值并在sort.ejs中设置,那么你应该使用<%- %>标签而不是<%= %>。

所以你的样子就像下面。

<hr id = "123" style="height:<%- hgt %>px;border-left: <%- width %>px solid black;float: left;margin-left:<%- margin %>px">

以下是一些关于ejs中不同标签的基本信息。

&lt;%= 将值输出到模板中(HTML转义)。

<%- 将未封装的值输出到模板中。

更多详情可参考此链接。EJS参考

© www.soinside.com 2019 - 2024. All rights reserved.