Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่าคุณสมบัติ Outline ทั้งหมดในประกาศเดียวด้วย JavaScript

ใช้คุณสมบัติ shorthand outline เพื่อกำหนดความกว้าง สไตล์ และสีของ outline พร้อมกัน รูปแบบ: width style color

ตัวอย่าง

<!DOCTYPE html>
<html>
  <head>
    <style>
      #box {
        width: 450px;
        background-color: orange;
        border: 3px solid red;
      }
    </style>
  </head>
  <body>
    <p>Click below to add Outline.</p>
    <div id="box">
      <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
      <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
      <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
    </div>
    <br>
    <button type="button" onclick="display()">Set Outline</button>
    <br>
    <script>
      function display() {
        document.getElementById("box").style.outline = "thick solid #5F5F5F";
      }
    </script>
  </body>
</html>