如何将EJS变量传递给Extern JS脚本
我的HTML页面上有一个脚本:
<script>
let a = <%-JSON.stringify(tags)%>
</script>
现在我在main.js文件上需要此变量。但是我不知道如何访问它
i have a script on my html page like that:
<script>
let a = <%-JSON.stringify(tags)%>
</script>
now I need this variable on my main.js file. But I don't know how I can access it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
window.a
,访问它,只要该脚本标签位于main.js
的脚本标签上方,但这需要一个在开始时设置值的不同方法。访问您的代码
You can access it with
window.a
, as long as that script tag is above the script tag formain.js
, but this requires a different way to set the value at the start.access in your code like