为什么我的JavaScript代码会发生这种情况?

发布于 2025-02-02 04:36:57 字数 637 浏览 3 评论 0原文

因此,这是我的代码:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <script type="module">
            import * as THREE from 'https://unpkg.com/[email protected]/build/three.module.js'
            const scene = new THREE.Scene
            console.log(scene)
        </script>
    </body>
</html>

它可以正常工作,但是一旦我将“ src =“ script.js”放到脚本标签)后,代码突然停止工作...有人可以向我解释为什么会发生这种情况?

so this is my code:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <script type="module">
            import * as THREE from 'https://unpkg.com/[email protected]/build/three.module.js'
            const scene = new THREE.Scene
            console.log(scene)
        </script>
    </body>
</html>

it works just fine but as soon as i put the "src="script.js" to the script tag, the code suddenly stops working... can somebody explain to me why this is happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

jJeQQOZ5 2025-02-09 04:36:57

每个脚本标签仅从src或从身体内部而不是两者都加载。您需要2个脚本标签来加载内联代码以及每个脚本文件中的一个。

Each script tag only loads from either src or from within the body, not both. You'll need 2 script tags to load the inline code as well as the script file in one of them each.

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