Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';不要让innerHTML在一个特定的位置工作。我不明白_Javascript_Innerhtml_Getelementbyid - Fatal编程技术网

Javascript Can';不要让innerHTML在一个特定的位置工作。我不明白

Javascript Can';不要让innerHTML在一个特定的位置工作。我不明白,javascript,innerhtml,getelementbyid,Javascript,Innerhtml,Getelementbyid,我不明白为什么函数attackGoblin不会写入我的HTML(上面的函数正在写入完全相同的空间,没有问题)。我根本无法让它写任何东西。这个函数运行得很好,我觉得完全一样 我喜欢一个星期,只是为了好玩而学习,但这让我发疯。另外,我知道我不应该用HTML编写脚本,但我现在正试图一步一步地完成。有人知道我要修什么吗?非常感谢 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t

我不明白为什么函数attackGoblin不会写入我的HTML(上面的函数正在写入完全相同的空间,没有问题)。我根本无法让它写任何东西。这个函数运行得很好,我觉得完全一样

我喜欢一个星期,只是为了好玩而学习,但这让我发疯。另外,我知道我不应该用HTML编写脚本,但我现在正试图一步一步地完成。有人知道我要修什么吗?非常感谢

   <!DOCTYPE html>
<html>

  <head>
<meta charset="utf-8">
<title>Status</title>
<link rel="stylesheet" type="text/css" href="reset.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
  </head>


  <body>
    <header>
      <h1>Stupid Game</h1>
    </header>

<div class="container">
  <table>
    <col width="90">
    <col width="90">
    <col width="600">
    <thead>
      <th colspan='2'>
        <h1>Status</h1>

      </th>
      <th colspan="2">
        <h1>Action

        </h1>
      </th>
      <tr>
        <th>
          <h2>HP</h2>
        </th>
        <th>
          <h2>
            <script>
              document.write(you._hp)

            </script>
          </h2>
        </th>
        <td id="actionTitle"> Click the door to enter the dungeon.</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="left">STR</td>
        <td class="left">
          <h3>
            <script>
              document.write(you._str)

            </script>
          </h3>
        </td>
        <td id="action" rowspan="5" colspan="4">
          <div id="actionLeft" onclick="goblinFight()"><img src="https://images-na.ssl-images-amazon.com/images/I/713sQo9DrQL.png" height="200" width="200">

          </div>
          <div id="actionMiddle"> </div>
          <div id="actionRight"> </div>

          <p id="combatMessage">Good Luck!</p>
        </td>



      </tr>
      <tr>
        <td class="left">INT</td>
        <td>
          <h3>
            <script>
              document.write(you._int)

            </script>
          </h3>
        </td>
      </tr>
      <tr>
        <td class="left">DMG</td>
        <td>
          <h3>
            <script>
              document.write(you._dmg)

            </script>
          </h3>
        </td>
      </tr>
      <tr>
        <td class="left">Status Effects</td>
        <td>
          <h3> - </h3>
        </td>
      </tr>
      <tr>
        <td class="left">Gold</td>
        <td>
          <h3>
            <script>
              document.write(you._gold)

            </script>
          </h3>
        </td>
      </tr>

    </tbody>
  </table>
</div>

<footer>

</footer>

地位
愚蠢的游戏
地位
行动
惠普
文档。写入(您。\u hp)
点击门进入地牢。
STR
文件。写(你。_str)
祝你好运

国际的 文件。写入(您。_int) DMG 文件。写入(您。\ dmg) 地位效应 - 黄金 文件。写(你。\金)


函数goblinFight(){
document.getElementById(“actionTitle”).innerHTML='A goblin!点击剑攻击或点击门逃跑';
document.getElementById(“actionLeft”).innerHTML='';
document.getElementById(“actionMiddle”).innerHTML='';
document.getElementById(“actionRight”).innerHTML='';
document.getElementById(“combatMessage”).innerHTML=''
}
函数(){
document.getElementById(“actionTitle”).innerHTML='记录您留下的内容';
document.getElementById(“actionLeft”).innerHTML='';
document.getElementById(“actionMiddle”).innerHTML='';
document.getElementById(“actionRight”).innerHTML='';
document.getElementById(“combatMessage”).innerHTML='写下您留下的任何东西';
}
函数攻击Goblin(){
document.getElementById(“combatMessage”).innerHTML='got him';
}
变量你={
_maxHp:12,
_惠普:12,
_str:10,
_国际:10,
_dmg:'5-8',
_金牌:0,,
_攻击:函数(){
返回Math.floor(Math.random()*5+4)
}
};
小妖精={
_惠普:8,
_金色:Math.random(Math.floor()*4),
_攻击:函数(){
返回Math.floor(Math.random()*3+2);
}
}

您需要查看控制台。在这里你可以知道你会犯什么样的错误。与大多数编程语言不同的是,如果网页由于错误而挂起,它们仍将尽其所能运行,并且不会在您的脸上留下错误窗口

如果您使用的是Chrome,查看控制台的最快方法是右键单击页面上的某个位置,然后选择
Inspect
。然后单击
控制台
选项卡

我想它会告诉您,您的
attackGoblin()
函数缺少一个右大括号:
}
。[编辑:正如多拉多所指出的,因为有一个结束的大括号,我现在不这么认为。]


祝你好运

第一次运行
goblinFight()
函数后,您将得到以下HTML结构:

<div id="actionLeft" onclick="goblinFight()">
   <div onclick="attackGoblin()">
      <img src="http://iconbug.com/data/80/256/5f0a7369c9651132688f02cbc49a7c28.png" width="120" height="120">
   </div>
</div>

希望这有帮助

请更新您的帖子以包含任何相关的HTML代码。当您在
attackGoblin()
函数中调用
innerHTML
时,实际会发生什么?我想我们需要知道这一点以帮助您。是否遇到任何错误?
goblinAttack()
函数在哪里,根据您的代码,您有不同的
attackGoblin()
。非常感谢您的有用评论。作为一个全新的人,我真的很感激你的善良和耐心。我用我所有(难看的)html和脚本重新发布。需要明确的是,当我在attackGoblin()函数中调用innerHTML时,什么也没有发生,这对我来说很奇怪,因为当我在逃跑()函数中调用它时,它写得非常好。有一个右括号。@Dorado就是这样,谢谢。不知道为什么它看起来不会滚动。
<div id="actionLeft" onclick="goblinFight()">
   <div onclick="attackGoblin()">
      <img src="http://iconbug.com/data/80/256/5f0a7369c9651132688f02cbc49a7c28.png" width="120" height="120">
   </div>
</div>
function attackGoblin(e) {
  document.getElementById("combatMessage").innerHTML = 'got him';
  e.stopPropagation(); // cancels the bubbling of the event passed into the function
}