对于js的引用一般有两种,第一种<script src='路径'>,另一种就是用type=module的形式,以下为type=module的使用实例
index.js:
export const sayHello = () => {
console.log("Hello")
}
example:
<!DOCTYPE html>
<html lang="en">
<body>
<script type="module">
import {sayHello} from "./index.js"
sayHello()
</script>
</body>
</html>
通过上例我们可以知道在script中添加type=module可以使用import关键词来引入js文件
博客介绍了JavaScript的两种引用方式,着重讲解了type=module形式,并给出使用实例,展示了在script中添加type=module后可用import关键词引入js文件。
497





