【问题标题】:Assigning value to input in ejs为ejs中的输入赋值
【发布时间】:2020-11-07 09:29:50
【问题描述】:

我想为输入字段赋值。当我console.log 时,我得到了输出,因为标题很适合应用程序。内容是你好世界。但是只有 Welcome 被分配给标题输入,只有 hello 被分配给内容输入。仅分配第一个单词。请帮忙。

post.ejs

<%- include('./partials/header');-%>
<%- include('./partials/flash');-%>

<form action="/posts/<%= post._id %>/edited" method="POST">
  <%= console.log("title is "+post.Title +" ."+"content is "+post.Content); %>
  <h1><input type="text" name="title" id="title" value=<%= post.Title %>></h1>
  <p><input type="text" name="content" id="content" value=<%= post.Content %>></p>
  <button class="btn btn-primary" type="submit">Publish</button>
</form>

<%- include('./partials/footer');-%>

【问题讨论】:

    标签: node.js mongodb express mongoose ejs


    【解决方案1】:

    将 ejs 变量括在引号内。

    //enclose like this
    value="<%= post.Title %>"
    value="<%= post.Content %>"
    
    <h1><input type="text" name="title" id="title" value="<%= post.Title %>"></h1>
    <p><input type="text" name="content" id="content" value="<%= post.Content %>"></p>
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2016-09-06
    • 2013-04-27
    • 1970-01-01
    相关资源
    最近更新 更多