如何一次用 JavaScript 設定所有四個邊框圓角屬性?


要在 JavaScript 中設定所有 border-radius 屬性,請使用 borderRadius 屬性。一次使用此屬性設定 border-radius 屬性。

示例

你可以嘗試執行以下程式碼來學習如何設定所有四個邊框圓角屬性 -

即時演示

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

更新於: 2020 年 6 月 23 日

118 次瀏覽

開始你的 職業

完成課程獲得認證

開始吧
廣告
© . All rights reserved.