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


要在 JavaScript 中為所有 border right 屬性設定值,請使用 borderRight 屬性。使用此屬性可以同時設定邊框顏色、樣式和寬度。

示例

你可以嘗試執行以下程式碼,學習如何一次性設定所有邊框右側屬性 −

線上演示

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