简体   繁体   English

需要来自 ejs 文件的 app.js 中 html 标记的 ID

[英]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.

相关问题 如何将数据从 * .ejs 文件传输到 app.js 并处理 app.js 文件上 HTML 标签上的点击事件 - How to transfer data from * .ejs file to app.js and handle click event on HTML tag on app.js file 将变量从 app.js 传递到 ejs 文件到脚本标签中 - Passing variable from app.js to ejs file into a script tag 如何通过app.js将另一个.js文件中所需的功能传递到index.ejs视图中 - How to pass function required from another .js file into an index.ejs view via app.js 如何将数据从一个 app.js 文件发送到 Routes 中的 index.ejs 文件 - how do I send data from one app.js file to index.ejs file in Routes 如何在app.js文件中包含EJS文件? - How to include an EJS file in app.js file? 如何在Node.js中将变量从ejs转换为app.js? - How can I take variable from ejs to app.js in Node.js? 如何在Node JS应用程序JavaScript中从index.html调用函数到app.js文件 - How to call a function from index.html to app.js file in node js application javascript 位于app.js中的服务器端对象标记为未在我的index.ejs文件中导出 - Server side object located in app.js marked as not exported in my index.ejs file 未捕获的ReferenceError:app.js中未定义require:3 - Uncaught ReferenceError: require is not defined at app.js:3 <a>从组件道具向 App.js 构造函数</a>添加<a>标签</a> - Adding <a> tag to App.js Constructor from Component Props
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM