【问题标题】:Score not showing on screen but only in the console log分数未显示在屏幕上,但仅显示在控制台日志中
【发布时间】:2021-09-10 22:33:06
【问题描述】:

Html 代码部分运行良好

   <div class =”flex-blackjack-row-3
       <table>
           <tr>
              <th>Wins</th>
              <th>Losses</th>
               <th> Draws</th>
           </tr>

           <tr>
               <td><span id=”wins”>0</span></td>
               <td><span id=”losses>0</span></td>
               <td><span id=”draws>0<</span></td>
           </tr>
    </div>

在 Javascript 代码中,除了 showScore 之外的所有其他代码都有效。 showScore 没有把分数放在那里。

function blackjackHit() {
   let card = randomCard();
   console.log(card);
   showCard(card, YOU);
   updateScore(card, YOU);
   showScore(card, YOU);
  }

function showScore(activePlayer) {
   Document.querySelector(activePlayer[‘scoreSpan’]).textContent = activePlayer[‘score’];

【问题讨论】:

  • 您的属性周围有花引号,它们必须是直引号。在class ="flex-blackjack-row-3 之后,您还缺少结束语
  • 还有Document应该是document
  • 这些是复制错误,还是你在真实代码中有这些问题?确保在编写代码时关闭“智能引号”。
  • activePlayer.scoreSpan的值是多少?

标签: javascript html function tags


【解决方案1】:

您在代码中遗漏了一些括号并使用了错误的引号。因此,您需要注意 HTML 和 Javascript 中的语法,因为通常浏览器会在没有建议的情况下消化您编写的所有代码。但是,您可以使用浏览器中的开发人员工具来检测其中一些问题。关于您的问题,请尝试使用以下代码来纠正这些问题:

HTML

<div class ="flex-blackjack-row-3">
       <table>
           <tr>
              <th>Wins</th>
              <th>Losses</th>
               <th> Draws</th>
           </tr>

           <tr>
               <td><span id="wins">0</span></td>
               <td><span id="losses">0</span></td>
               <td><span id="draws">0</span></td>
           </tr>
    </div>

Javascript

function blackjackHit() {
   let card = randomCard();
   console.log(card);
   showCard(card, YOU);
   updateScore(card, YOU);
   showScore(card, YOU);
  }

function showScore(activePlayer) {
   document.querySelector(activePlayer['scoreSpan']).textContent = activePlayer['score'];
}

【讨论】:

    猜你喜欢
    • 2021-03-12
    • 2017-03-13
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    相关资源
    最近更新 更多