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

วิธีตั้งค่าคุณสมบัติเส้นคอลัมน์ (column rule) ด้วย JavaScript

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

ตัวอย่าง

<!DOCTYPE html>
<html>
  <body>
    <p>Click below to create 4 columns</p>
    <button onclick="display()">Columns</button>
    <div id="myID">
      This is demo text. This is demo text. This is demo text. This is demo text.
      This is demo text. This is demo text. This is demo text. This is demo text.
      This is demo text. This is demo text. This is demo text. This is demo text.
      This is demo text. This is demo text. This is demo text. This is demo text.
      This is demo text. This is demo text. This is demo text. This is demo text.
      This is demo text. This is demo text. This is demo text. This is demo text.
      This is demo text. This is demo text. This is demo text. This is demo text.
    </div>
    <script>
      function display() {
        document.getElementById("myID").style.columnCount = "4";
        document.getElementById("myID").style.columnRule = "2px outset red";
      }
    </script>
  </body>
</html>