如何用 JavaScript 設定或返回元素應分為多少列的內容?
要將 div 分為三列,請使用 columnCount 屬性設定列數並對 div 進行分割。
示例
您可以嘗試執行以下程式碼,使用 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"; } </script> </body> </html>
廣告