你能帮我解决这个问题吗?第一个 div 的 bg-color 只是在改变,但其余的不起作用帮助我解决这个问题!
const hexNum = [0,1,2,3,4,5,6,7,8,'A','B','C','D','E','F'];
const hexBtn = document.querySelector('.btn-hex');
const bgPale = document.querySelector('.bg-color');
const hexCode = document.querySelector('.color-code');
hexBtn.addEventListener('click', getNewHex);
function getNewHex(){
let newHexCode = '#';
for (let i = 0; i<6; i++){
let randomHex = Math.floor(Math.random()*hexNum.length);
newHexCode +=hexNum[randomHex];
//console.log(newHexCode);
}
bgPale.style.backgroundColor = newHexCode;
hexCode.innerHTML = newHexCode
}
<div class="bg-color palette-1"></div>
<div class="bg-color palette-2"></div>
<div class="bg-color palette-3"></div>