为什么我的JavaScript代码会发生这种情况?
因此,这是我的代码:
<!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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
每个脚本标签仅从
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.