三个JS的多个脚本标签

发布于 2025-01-25 19:02:50 字数 633 浏览 0 评论 0原文

我正在尝试与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁人与我共长歌 2025-02-01 19:02:50

请尝试此选项:在您的主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

铁轨上的流浪者 2025-02-01 19:02:50

尝试替换

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文