为什么我的进口&导出与我的JS文件一起工作

发布于 2025-02-05 05:57:19 字数 689 浏览 1 评论 0原文

因此,我从JS中的导入和导出开始,但是我不明白为什么我的代码不起作用。

这是我的html文件:

<body>
    <button id="changecolor"></button>
    <script type="module" src="./JSWebTesting.js"> </script>
</body>

这是我的jswebtesting文件:

"use strict";

import { toColor } from './JSWebTesting2.js';

document.getElementById('changecolor').addEventListener('click', () => {
    toColor('green');
})

这是我的jswebtesting2文件:

"use strict";

function toColor(color) {
    document.body.style.backgroundColor = color;
}

export { toColor }

没有错误消息出现,我将Console.Logs.logs放入两个JS文件中,但在控制台中没有出现。我不明白我的代码出了什么问题。

So I'm starting with import and export in JS, but I don't understand why my code isn't working.

This is my HTML file:

<body>
    <button id="changecolor"></button>
    <script type="module" src="./JSWebTesting.js"> </script>
</body>

This is my JSWebTesting file:

"use strict";

import { toColor } from './JSWebTesting2.js';

document.getElementById('changecolor').addEventListener('click', () => {
    toColor('green');
})

This is my JSWebTesting2 file:

"use strict";

function toColor(color) {
    document.body.style.backgroundColor = color;
}

export { toColor }

No error message comes up, and I put console.logs into both JS files, but nothing came up in console. I don't understand what is going wrong with my code.

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

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

发布评论

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