0
0

オブジェクトのメソッドとプロパティの整理

Posted at
<body>
  <header>
    <div class="container">
      <h1>タイトル</h1>
      <h2>サブタイトル</h2>
    </div><!-- /.container -->
  </header>
  <main>
    <div class="container">
      <section>
-        <p id="choice">ここに日時を表示します</p>
      </section>
    </div><!-- /.container -->
  </main>
  <footer>
    <div class="container">
      <p>JavaScript Samples</p>
    </div><!-- /.container -->
  </footer>
+  <script>
+    'use script';
+   document.getElementById('choice').textContent = new Date();
+    console.log(document.getElementById('choice').textContent);
+  </script>
</body>

オブジェクトにはwindowsオブジェクトdocumentオブジェクトconsoleオブジェクトなどがあり、それぞれには固有のメソッド、プロパティが存在する。

メソッド:オブジェクトにさせたい指示する 例)  log()やById()
プロパティ:オブジェクトの状態を表す 例)  textContent
パラメータ:()内に含まれる文字列や数列 例)  textContent

//documentオブジェクト内のid名を取得して、id名のコンテンツを日付(new Date())に書き換える
document.getElementById('choice').textContent = newDate();

//documentオブジェクト内のid名を取得して、読み取り。consoloに表示させる。
console.log(document.getElementById('choice').textContent);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0