如何用 JavaScript 設定輪廓顏色?


若要設定輪廓顏色,請在 JavaScript 中使用 outlineColor 屬性。你可以嘗試執行以下程式碼來學習如何實現 outlineColor 屬性 -

示例

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
      #box {
         border: 2px solid red;
      }
      </style>
   </head>
   
   <body>
      <div id = "box">
         Demo Content
      </div>
      <br>
      
      <button type = "button" onclick = "display()">Change outline color</button>
      <script>
         function display() {
            document.getElementById("box").style.outlineColor = "#FF5733";
            document.getElementById("box").style.outline = "2px solid";
         }
      </script>
   </body>
</html>

更新日期:2019 年 7 月 30 日

424 次瀏覽

開啟你的 職業

完成課程後獲得認證

開始
廣告