如何使用 JavaScript 在一個宣告中設定所有邊框右側的屬性?


在 JavaScript 中設定所有 border(邊框)右側屬性,請使用 **borderRight** 屬性。使用此屬性,可一次性設定邊框顏色、樣式和寬度。

示例

你可以嘗試執行以下程式碼,瞭解如何一次性設定所有 border(邊框)右側屬性 −

線上演示

<!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 right border</button>
      <script>
         function display() {
            document.getElementById("box").style.borderRight = "thick solid #000000";
         }
      </script>
   </body>
</html>

更新於:2020 年 6 月 23 日

142 次瀏覽

開啟你的 職業生涯

透過完成本課程進行認證

開始
廣告
© . All rights reserved.