Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Javascript

กำหนดจำนวนคอลัมน์ที่องค์ประกอบควรขยายข้ามด้วย JavaScript


ตั้งค่า columnSpan คุณสมบัติทั้งหมด หากคุณต้องการให้คอลัมน์ขยายออกไปใน JavaScript คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อส่งคืนจำนวนคอลัมน์ที่องค์ประกอบควรข้ามด้วย JavaScript -

ตัวอย่าง

<!DOCTYPE html>
<html>
   <head>
      <style>
         #myID {
            column-count: 4;
         }
      </style>
   </head>
   
   <body>
      <p>Note- The columnSpan property won't work in Firefox.</p>
      <button onclick = "display()">Span Columns</button>
      <div id = "myID">
         <h1 id = "h1ID">Heading Level 1 for Demo</h1>
         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("h1ID").style.columnSpan = "all";
         }
      </script>
      
   </body>
</html>