为什么我的进口&导出与我的JS文件一起工作
因此,我从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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论