javascript is not working

Asked 1 years ago, Updated 1 years ago, 29 views

I'm a complete beginner.
I bought the book this time and immediately moved the sample code, but the javascript part was not reflected at all.
The code is as follows.
I would appreciate it if you could let me know the possible causes.

<!DOCTYPE HTML>
<html>
<head>
    <metacharset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scale=no">
    <meta http-equiv="Content-Security-Policy" content="default-src*data:;style-src*'unsafe-inline';script-src*'unsafe-inline'"unsafe-eval'">
    <script src="components/loader.js"></script>
    <link rel="stylesheet" href="components/loader.css">
    <link rel="stylesheet" href="css/style.css">
    <script>
        document.addEventListener("DOMCintentLoaded", function(){
            var nowDate = new Date();
            varfullYear=nowDate.getFullYear();
            var shortYear=Striong(fullYear).substr(2,2);
            var heiseiYear=Number(shortYear)+12;
            document.getElementByID("heisei-year").textContent=heiseiYear;
            document.getElementByID("year").textContent=fullYear;
        });
    </script>

</head>
<body>
 <br of >
    <divid="heisei">
        This year is Heisei<span id="heisei-year">/span> year.
    </div>
    <divid="ad">A.D.<spanid="year"></span>>  
</body>
</html>

javascript

2022-09-30 20:19

1 Answers

There are some typographical errors in the code in the question, especially because the event name is incorrect.

  • DOMCintentLoaded→DOMContentLoaded
  • Striong→String
  • getElementByID→getElementById

In addition, the first problem is that you are registering for an event that does not occur, so there is no error, but the other two will be printed in the browser's Developer Tool when the event is run.


2022-09-30 20:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.