在HTML文件中包括JavaScript模块。 (香草JavaScript)

发布于 2025-02-08 02:48:48 字数 749 浏览 0 评论 0原文

我有一个多文件网页,但是我只想要一个文件(index.html)。因为这似乎是使用Android WebView显示它的最简单方法。我有一个JavaScript文件JavaScript模块和HTML文件。

    <!DOCTYPE html>
<html>
<body>
    <script type="module">import * as Module from './Module.js';</script>
</body>
</html>

我知道如何在网页中包含普通脚本,但是如何将模块模块嵌入index.html中。

我想做这样的事情...

    <!DOCTYPE html>
<html>
<body>
    <script type="module" src="Module.js">
        export function CallHello(){
            console.log("Hello");
        }
    </script>
    <script type="module">
        import * as Module from './Module.js';
        Module.CallHello();
    </script>
</body>
</html>

I have a multi file webpage, but I just want one file (index.html). because this seems the easiest way to display it using android webview. I have a javascript file a javascript module and the html file.

    <!DOCTYPE html>
<html>
<body>
    <script type="module">import * as Module from './Module.js';</script>
</body>
</html>

I know how to include normal scripts in the webpage, but how do I embed the module Module.js in index.html.

I want to do something like this...

    <!DOCTYPE html>
<html>
<body>
    <script type="module" src="Module.js">
        export function CallHello(){
            console.log("Hello");
        }
    </script>
    <script type="module">
        import * as Module from './Module.js';
        Module.CallHello();
    </script>
</body>
</html>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文