如何用 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>
广告