-2

我在输出中得到的只是未定义 changeColor 和未定义 changeAgain。我试图修复它,但它似乎不起作用。任何帮助将不胜感激,我到处都看过!!!

这是我的代码

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>

<body onLoad="alert('Website Loaded');">

  <script language="javascript" type="text/javascript">
    function changeColor() {
      document.GetElementById("h3style").style.color = "red";
      document.GetElementById("h3style").firstChild.nodeValue = "RED!";
      return true;
    }

    function changeAgain() {
      document.GetElementById("h3style").style.color = "gray";
      document.GetElementById("h3style").firstChild.nodeValue = "Gray...";
      return true;
    }
  </script>
  <noscript>
    <h1>THIS CONTENT REQUIRES JAVASCRIPT | PLEASE ENABLE JAVASCRIPT</h1>
  </noscript>


  <h3 id="h3style" onMouseOver="changeColor()" onMouseOut="changeAgain()">Scroll on me</h3>

</body>

</html>

4

1 回答 1

1

应该是getElementById

在此处查看文档

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>

<body onLoad="alert('Website Loaded');">

  <script language="javascript" type="text/javascript">
    function changeColor() {
      document.getElementById("h3style").style.color = "red";
      document.getElementById("h3style").firstChild.nodeValue = "RED!";
      return true;
    }

    function changeAgain() {
      document.getElementById("h3style").style.color = "gray";
      document.getElementById("h3style").firstChild.nodeValue = "Gray...";
      return true;
    }
  </script>
  <noscript>
    <h1>THIS CONTENT REQUIRES JAVASCRIPT | PLEASE ENABLE JAVASCRIPT</h1>
  </noscript>


  <h3 id="h3style" onMouseOver="changeColor()" onMouseOut="changeAgain()">Scroll on me</h3>

</body>

</html>

于 2015-03-08T18:39:51.333 回答