如何用 JavaScript DOM 建立表格標題?


要建立表格標題,請使用 DOM createCaption() 方法。

舉例

你可以嘗試執行以下程式碼,瞭解如何建立表格標題 −

線上演示

<!DOCTYPE html>
<html>
   <head>
      <script>
         function captionFunc(x) {
            document.getElementById(x).createCaption().innerHTML = "Demo Caption";
         }
      </script>
   </head>
   <body>
      <table style="border:2px solid black" id="newtable">
         <tr>
            <td>One</td>
            <td>Two</td>
         </tr>
         <tr>
            <td>Three</td>
            <td>Four</td>
         </tr>
         <tr>
            <td>Five</td>
            <td>Six</td>
         </tr>
      </table>
      <p>
         <input type="button" onclick="captionFunc('newtable')" value="Display Table Caption">
      </p>
   </body>
</html>

更新日期:2020-06-23

閱讀次數:454

助力您的職業生涯

透過完成課程進行認證

開始
廣告
© . All rights reserved.