【问题标题】:EJS HTML Render With Greater Than (>) SymbolEJS HTML 呈现大于 (>) 符号
【发布时间】:2021-03-07 21:35:56
【问题描述】:

**在我转到根路由后,h1 和段落被渲染,但它使用 > Symbol Any Solution 渲染没有 > 符号 **

const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
var posts = [];
const app = express();

app.set('view engine', 'ejs');

app.get("/", function(req, res){
  res.render("home", {Content : homeStartingContent, posts: posts});
  
});
app.get("/compose", function(req, res){
  res.render("compose");
});

app.post("/compose",bodyParser.urlencoded({extended: true}),function(req, res){
  let Post = {
    PostTitle: req.body.Title,
    Content: req.body.Content, 
  };
  posts.push(Post);
  res.redirect("/");
  
});


app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));

app.listen(3000, function() {
  console.log("Server started on port 3000");
});
<%- include("Partials/header") %>

<h1>Home</h1>
<p><%= Content %></p>



    <% posts.forEach(function(post){ %>
    <h1>><%=post.PostTitle%></h1> 
    <p>><%=post.Content%></p> 
 <%   }); %>


<%- include("Partials/footer") %>

【问题讨论】:

    标签: javascript node.js ejs


    【解决方案1】:

    您错误地包含了&gt;。 应该是

    <h1><%=post.PostTitle%></h1> 
    <p><%=post.Content%></p>
    

    不是

    <h1>><%=post.PostTitle%></h1> 
    <p>><%=post.Content%></p>
    

    【讨论】:

      【解决方案2】:

      这是你的问题

      <h1>><%=post.PostTitle%></h1>
          ^ 
      <p>><%=post.Content%></p>
      

      【讨论】:

        猜你喜欢
        • 2023-03-20
        • 1970-01-01
        • 2016-02-15
        • 1970-01-01
        • 1970-01-01
        • 2012-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多