Computer >> Máy Tính >  >> Lập trình >> Javascript

Làm thế nào để điền vào các cột bằng JavaScript?


Sử dụng columnFill thuộc tính để điền vào các cột. Điền nó là tự động điền tuần tự hoặc cân bằng để chia đều nội dung giữa các cột.

Ví dụ

Bạn có thể thử chạy mã sau để đặt các cột lấp đầy bằng JavaScript -

<!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.columnFill = "balance";
         }
      </script>
   </body>
</html>