如何在 JavaScript 中使用一個宣告設定 border 寬度、樣式和顏色?


要在單個宣告中設定邊框寬度、樣式和顏色,請在 JavaScript 中使用 border 屬性。

示例

你可以嘗試執行以下程式碼,瞭解如何在 JavaScript 中設定邊框−

線上演示

<!DOCTYPE html>
<html>
   <body>
      <button onclick="display()">Set border</button>
      <div id="box">
         <p>Demo Text</p>
         <p>Demo Text</p>
      </div>
      <script>
         function display() {
            document.getElementById("box").style.border = "thick dashed #000000";
         }
      </script>
   </body>
</html>

更新於: 2020 年 6 月 23 日

882 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

馬上開始
廣告
© . All rights reserved.