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

Đặt số lượng cột mà một phần tử sẽ trải dài bằng JavaScript.

Đặt columnSpan cho tất cả, nếu bạn muốn các cột kéo dài trong JavaScript. Bạn có thể thử chạy đoạn mã sau để trả về số lượng cột mà một phần tử sẽ trải qua bằng JavaScript -

Ví dụ

<!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>