[英]Require Id of html tag in app.js from ejs file
sort.ejs file code 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 file code 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){
}
I want to print the value of style elements(height, margin) of the hr tag in sort.ejs file in my terminal when the post request gets triggered.当发布请求被触发时,我想在终端的 sort.ejs 文件中打印 hr 标签的样式元素(高度、边距)的值。 All the variables used in sort.ejs are predefined.
sort.ejs 中使用的所有变量都是预定义的。
I am using Node.js and EJS.我正在使用 Node.js 和 EJS。
I'm bit confused about your Query.我对你的查询有点困惑。 but if you're asking about how to get value from app.js and set in sort.ejs then you should use <%- %> tag instead of <%= %>.
但是如果你询问如何从 app.js 中获取价值并在 sort.ejs 中设置,那么你应该使用 <%- %> 标签而不是 <%= %>。
so your look like below:所以你看起来像下面:
<hr id = "123" style="height:<%- hgt %>px;border-left: <%- width %>px solid black;float: left;margin-left:<%- margin %>px">
Here are some basic info about different tags in ejs.以下是有关 ejs 中不同标签的一些基本信息。
<%= Outputs the value into the template (HTML escaped) <%=将值输出到模板中(HTML 转义)
<%- Outputs the unescaped value into the template <%-将未转义的值输出到模板中
For more details you can refer this link: EJS Reference有关更多详细信息,您可以参考此链接: EJS 参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.