三个JS的多个脚本标签
我正在尝试与Trix.js合作,而实际上是第一次只是HTML和JS。我正在使用示例代码播放,并且发现即使我从main.js文件中的脚本标签中导入了三个文件,除非我取消注册脚本标签,否则它行不通。为什么这样?无论如何,我是否可以在没有第一个脚本标签的情况下仅在我的main.js文件中运行它?
<!DOCTYPE html>
<html>
<head>
<!-- <meta charset="utf-8"> -->
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<!-- <script src="node_modules\three\build\three.js"></script> -->
<script src="js/Main.js"></script>
</body>
</html>
I'm trying to work with three.js and really just html and js in general for the first time. I'm playing around with the example code and I found that even if I import the three.js file from the script tag in my Main.js file, it doesn't work unless I uncomment the script tag currently commented out. Why is this the case? Is there anyway i can run it in just my Main.js file without the first script tag?
<!DOCTYPE html>
<html>
<head>
<!-- <meta charset="utf-8"> -->
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<!-- <script src="node_modules\three\build\three.js"></script> -->
<script src="js/Main.js"></script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请尝试此选项:在您的主HTML页面
&lt; script type =“ module” src =“ js/main.js”&gt;&lt;/script&gt;
un JS页面please try this option: in your main html page
<script type="module" src="js/Main.js"></script>
and in your main.js page import other js pages尝试替换
script src =“ node_module/threx/build/build/threx
;
&lt ; /build/three.module.js"&gt;&lt ;/script>
如果导入模块功能,则应将其声明为模块。
(不确定为什么type =“模块”应该是标签
&lt; script src =“ js/main.js”&gt;&lt;/script&gt;
否则功能要在其之外使用。)
Try replacing
<script src="node_module/three/build/three.js"></script>
with
<script type="module" src="node_module/three/build/three.module.js"></script>
If you are importing module functions, it should be declared as a module.
(Not sure why type="module" should be part of the tag
<script src="js/Main.js"></script>
unless Main.js is exporting functions to be used outside of it.)