当使用ejs格式时,js中的Document的替代品是什么



我正在使用ejs来做我的html内容,不能在这里使用常规的document.getElementById('id'(内容。

它说文件没有定义。

所以我想知道它的替代品是什么??

这是代码:

<% var formToAttach = document.getElementById('formToAttach'); %>
<% var selectElement = document.createElement('select'); %>
<% selectElement.id = "states"; %>
<% selectElement.setAttribute('name','search'); %>
<% var option = document.createElement('option'); %>
<% option.setAttribute('value', placeName["loc"]); %>
<% selectElement.appendChild(option); %>
<% formToAttach.appendChild(selectElement); %>

您必须将它们放在普通的<script>标记中,而不是ejs标记中。

请看另一篇关于类似问题的帖子:

我应该在ejs文件中使用脚本标记吗?

最新更新