Html introduces ejs template to report error

  1. according to the node.js authoritative guide, type the code and introduce the ejs template code
  2. part of ejs code
<script type="text/javascript" src="../node_modules/ejs/lib/ejs.js"></script>

    <script>
        function window_onload() {
            <% if (errMsg) { %>
                document.getElementById("msg").innerHTML = "<%=errMsg%>";
            <%} else if (successMsg) {%>
                document.getElementById("msg").innerHTML = "<%=successMsg>";
            <%} else {%>
                document.getElementById("msg").innerHTML = "";
            <%} if (code == "") {%>
                document.getElementById("tbxDate").value = new Date().toJSON.slice(0, 10);
            <%} else {%>
                document.getElementById("tbxCode").value = "<%=order.code%>";
                document.getElementById("tbxDate").value = "<%=order.date.toJSON().slice(0,10)%>";
                document.getElementById("tbxGoodsCode").value = "<%=order.goodsCode%>";
                document.getElementById("tbxBrandName").value = "<%=order.brandName%>";
                document.getElementById("tbxNum").value = "<%=order.num%>";
                document.getElementById("tbxPrice").value = "<%=order.price%>";
                document.getElementById("tbxMoney").value = "<%=order.num*order.price%>";
                document.getElementById("tbxPersonName").value = "<%=order.personName%>";
                document.getElementById("tbxEmail").value = "<%=order.email%>";
                <%if (!errMsg) {%>
                    document.getElementById("tbxCode").setAttribute("readonly", true);
                <%}%>
            <%}%>
        }

3. Compiler reports an error

4.

<script type="text/javascript" src="../node_modules/ejs/lib/ejs.js"></script>

5.

Jul.03,2021

this is a mix of front-end and back-end code, and errors reported by IDE may be ignored.

successMsg is followed by %


If the

script tag does not add the type attribute, the default is text/javascript, and your segment is ejs, without rendering. The browser defaults to js parsing, of course, it will report an error.

I don't know how to use your ejs here. If you simply want it not to report an error, add a type attribute (such as text/ejs), as long as it is not a text/javascript, browser that does not recognize it, it will not report an error.

< hr >

seems to have got the wrong answer. You can save the editor as ejs or specify ejs parsing.

Menu