【发布时间】:2018-06-01 19:29:33
【问题描述】:
当我有带有导出语句的 extern javascript 文件时,如何在 HTML 中调用它?
-
<script>标记中的导入也不起作用。 -
<head>上的包含给我一个“意外的令牌导出”错误
例如: 我的外部 js 文件
export function myFunction(text) { return text; }
我的 HTML:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="myExternFile.js"> </script>
</head>
<body>
<script>
console.log(myFunction("some text"));
</script>
</body>
</html>
【问题讨论】:
-
这不是
export的预期行为,您也不需要export进行此类函数调用。删除export,您的代码必须可以正常工作。 -
这个问题可能与this question重复。
标签: javascript html