我希望代码能随机显示图片。
尝试通过JavaScript DOM在我的HTML中放置随机图像,但该图像未在浏览器中显示。我收到错误net::ERR_FILE_NOT_FOUND Image (async) (anonymous)
@ app.js:14
控制台告诉问题出在diceDOM.src = 'dice-' + dice + '.png';
这是代码:
var scores, roundScore, activePlayer;
scores = [0,0];
roundScore = 0;
activePlayer = 1;
document.querySelector('.dice').style.display = 'none';
document.querySelector('.btn-roll').addEventListener('click', function(){
//1. Random Number
var dice = Math.floor(Math.random () * 6) + 1;
//2. Display the Results
var diceDOM = document.querySelector('.dice');
diceDOM.style.display = 'block';
diceDOM.src = 'dice-' + dice + '.png';
});