我試圖通過創(chuàng)建一個(gè)新的 div 來打印 img,然后將其附加到圖像,但圖像沒有顯示。JS 這里 rpsGame 是主函數(shù),調(diào)用了 rpsFrontEnd 函數(shù),并且 rpsFrontEnd 的參數(shù)是正確的。function rpsGame(yourChoice) { var humanChoice = yourChoice.id; var botChoice = noToChoice(randTorpsInt()); console.log("bot choice " + botChoice); console.log("your choice " + humanChoice); var results = decideWinner(humanChoice, botChoice); console.log(results); var message = finalMessage(results); console.log(message); rpsFrontEnd(humanChoice, botChoice, message);}這個(gè) rpsFrontend 首先刪除所有圖像,然后創(chuàng)建一個(gè)新的 div 并在其中附加一個(gè) img,但 img 沒有被打印function rpsFrontEnd(humanImageChoice, botImageChoice, finalMessage) { var imageDatabase = { "rock": document.getElementById("rock").src, "paper": document.getElementById("paper").src, "scissor": document.getElementById("scissor").src } document.getElementById("rock").remove(); document.getElementById("paper").remove(); document.getElementById("scissor").remove(); var humanDiv = document.createElement("div"); var botDiv = document.createElement("div"); var messageDiv = document.createElement("div"); humanDiv.innerHTML="<img src'"+imageDatabase[humanImageChoice]+"'>"; console.log(humanDiv); document.getElementById("col").appendChild(humanDiv);}謝謝你的時(shí)間!
附加圖像到 div 未顯示
森林海
2024-01-18 15:44:33