如何在 HTML 中為元素新增唯一 id?


使用 HTML 中的id 屬性為元素新增唯一 id。

例項

你可以嘗試執行以下程式碼來實現 id 屬性 -

<html>
   <body>
      <h1>Tutorialspoint</h1>
      <p id = "myid">We provide Tutorials!</p>
      <button onclick = "display()">More...</button>

      <script>
         function display() {
            document.getElementById("myid").innerHTML = "We provide learning videos as well";
         }
      </script>
   </body>
</html>

更新於: 24-06-2020

841 次瀏覽

開拓你的 事業

完成課程以獲得認證

開始
廣告