使用 JavaScript 如何更改表格邊框的寬度?


要更改表格邊框的寬度,請使用 DOM border 屬性。你可以嘗試執行以下程式碼在 JavaScript 中更改表格邊框的寬度 −

示例

<!DOCTYPE html>
<html>
   <head>
      <script>
         function borderFunc(x) {
            document.getElementById(x).style.border = "5px dashed blue";
         }
      </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 = "borderFunc('newtable')"
         value = "Change Border Width">
      </p>
   </body>
</html>

更新於: 23-6 月-2020

826 瀏覽

開啟您的 職業生涯

學習完成課程獲得認證

開始
廣告
© . All rights reserved.