【发布时间】:2022-10-23 18:18:03
【问题描述】:
我不知道如何解决这个错误,是创建一个模块还是什么。由于我正在使用浏览器,因此 Require JS 将不起作用。如何使用基于客户端的代码解决此错误?我需要安装软件包来解决它吗?请帮忙。
顺便说一句,我的 JS 代码:
import floor from 'mathjs';
import random from 'mathjs';
var colorValue = Array("#000000", "#000000", "#000000");
const hexadecimal = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D","E","F");
listening();
function listening() {
document.getElementById("changeColorOne").addEventListener(click, changeColor1);
document.getElementById("changeColorTwo").addEventListener(click, changeColor2);
document.getElementById("changeColorThree").addEventListener(click, changeColor3);
}
function changeColor1() {
document.querySelector(".square1").style.background = colorValue[0];
colorValue[0] = colorDecide();
}
function changeColor2() {
document.querySelector(".square2").style.background = colorValue[1];
colorValue[1] = colorDecide();
}
function changeColor3(){
document.querySelector(".square3").style.background = colorValue[2];
colorValue[2] = colorDecide();
}
function colorDecide() {
var tempValue = "#";
for (var i = 1; i <= 6; i++) {
let x = floor(random() * 16);
tempValue = tempValue.concat(hexadecimal[x]);
}
return tempValue;
}
【问题讨论】:
-
在脚本标签中添加
type="module" -
@konradLinkowski 你是什么意思?
-
显示你的脚本标签
-
或者这是您在节点中遇到的错误?在这种情况下,请参阅SyntaxError: Cannot use import statement outside a module
标签: javascript import module