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

วิธีเติมเนื้อหาในคอลัมน์ด้วย JavaScript


ใช้คุณสมบัติ columnFill เพื่อเติมเนื้อหาในคอลัมน์ ตั้งค่าเป็น auto เพื่อเติมตามลำดับ หรือ balance เพื่อแบ่งเนื้อหาเท่าๆ กันระหว่างคอลัมน์

ตัวอย่าง

คุณสามารถลองรันโค้ดต่อไปนี้เพื่อตั้งค่าเติมคอลัมน์ด้วย 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>