如何用 JavaScript 在一次宣告中設定所有邊框頂部屬性?


要透過一次宣告設定所有邊框頂部屬性,請使用 borderTop 屬性。透過此屬性,可以設定 border-top-width、border-top-style 和 border-top-color 屬性。

示例

可以嘗試執行以下程式碼,瞭解如何使用 JavaScript 中的邊框頂部屬性 −

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            border: thick solid gray;
            width: 300px;
            height: 200px
         }
      </style>
   </head>
   <body>
      <div id="box">Demo Text</div>
      <br><br>
      <button type="button" onclick="display()">Change top border</button>
      <script>
         function display() {
            document.getElementById("box").style.borderTop = "thick solid #000000";
         }
      </script>
   </body>
</html>

更新於: 2020 年 6 月 23 日

208 次瀏覽

開啟您的 職業 生涯

完成課程後獲得認證

立即開始
廣告
© . All rights reserved.