亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用文字改變圖像

用文字改變圖像

慕容森 2023-11-02 19:58:06
我正在制作一款游戲,根據玩家所做的選擇,它將顯示新的文本供選擇。我正在嘗試將圖像與該文本連接起來,以便它們能夠適應每個選擇?,F在,我的文字可以正常工作,但我的圖像無法顯示。我在這里做錯了什么?  <script type ="text/javascript">    const textElement = document.getElementById('text')    const optionButtonsElement = document.getElementById('option-      buttons')        let state = {}    function startGame() {        state = {}        showTextNode(1)                         }      function showTextNode(textNodeIndex) {      const textNode = textNodes.find(textNode => textNode.id ===      textNodeIndex)      textElement.innerText = textNode.text      document.getElementById('img').src=textNode.img      while (optionButtonsElement.firstChild) {         optionButtonsElement.removeChild(optionButtonsElement.firstChild)        }        textNode.options.forEach(option => {            if (showOption(option)) {            const button = document.createElement('button')            button.innerText = option.text            button.classList.add('btn')            button.addEventListener('click', () =>             selectOption(option))            optionButtonsElement.appendChild(button)                }            })         }        function showOption(option) {        return option.requiredState == null ||         option.requiredState(state)            }        function selectOption(option) {        const nextTextNodeId = option.nextText        if (nextTextNodeId <= 0) {        return startGame()            }        state = Object.assign(state, option.setState)        showTextNode(nextTextNodeId)            }              const textNodes = [        {        id: 1,        Image:url('invitation.jpg'),        text: "You are cordially invited to celebrate Sir Troy         Bennet's 70th birthday! RSVP to attend the event this         evening at the Cherry Hill mansion.",        options: [        {        text: 'RSVP',        nextText: 2        },        {        text: "I'm going to stay home",        nextText: 24        }         ]          },
查看完整描述

1 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

這將需要更多上下文,例如 JSFIDDLE 或 CODEPEN 上的可重現示例...但是根據我所看到的代碼所說;

textNode.img

當你在尋找時;

textNode.Image

17號線;

document.getElementById('img').src=textNode.img

所以你必須像上面提到的那樣改變Image:url('invitation.jpg'),為beimg:url('invitation.jpg'),或更新textNode.img為be textNode.Image。


查看完整回答
反對 回復 2023-11-02
  • 1 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號