如何在 JavaScript 中使用一次宣告來設定所有 border-top 屬性?


若要在一個宣告中設定所有 border-top 屬性,請使用 borderTop 屬性。使用該屬性,可以設定 border-top-width、border-top-style 和 border-top-color 屬性。

示例

可以嘗試執行以下程式碼,以瞭解如何在 JavaScript 中使用 border-top 屬性 -

即時演示

<!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>

更新於: 23-6-2020

208 次瀏覽

開啟您的 職業

完成課程獲得認證

開始
廣告
© . All rights reserved.