search

Home  >  Q&A  >  body text

javascript - Error reporting when introducing js into ejs


How to solve this error

I want to display alert() in ejs, similar to this
http://stackoverflow.com/ques...

大家讲道理大家讲道理2835 days ago429

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:21:17

    Remove the <%= if (msg){ %>= in the first line.

    • <% JavaScript 控制代码,不输出 %>

    • <%= 输出值 (HTML escaped) %>

    • <%- 输出值,原样输出 %>

    reply
    0
  • 阿神

    阿神2017-05-19 10:21:17

    <body>
    
    <% if (msg){ %>
    <p><%= msg %></p>
    <% } %>
    
    <input id="msg" type="hidden" value="<%= msg %>">
    
    <script>
    
      var msg = document.querySelector('#msg').value;
      console.log(msg);
    
    
      alert(<%= msg%>);
      
      var msg1 = <%= msg%>;
      console.log(msg1);
      
    </script>

    reply
    0
  • Cancelreply