HTML DOM cols 属性

定义和用法

cols 属性可设置或返回框架集中列的数目和尺寸。

由逗号分割的像素或百分比列表定义了列的数目和宽度:

语法

  1. framesetObject.cols=col1,col2,col3....

实例

在我们的例子中,首先将创建包含带有两个列的框架集的 HTML 文档。每列设置为浏览器窗口的 50%:

  1. <html>
  2. <frameset cols="50%,50%">
  3. <frame src="frame_cols.htm">
  4. <frame src="frame_a.htm">
  5. </frameset>
  6. </html>

HTML 文档 "frame_cols.htm" 被放入第一列,而 HTML 文档 "frame_a.htm" 被放入第二列。

下面是 "frame_cols.htm" 的源代码:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function changeCols()
  5. {
  6. parent.document.getElementById("main").cols="30%,70%"
  7. }
  8.  
  9. function restoreCols()
  10. {
  11. parent.document.getElementById("main").cols="50%,50%"
  12. }
  13. </script>
  14. </head>
  15. <body>
  16.  
  17. <input type="button" onclick="changeCols()"
  18. value="Change column size" />
  19. <input type="button" onclick="restoreCols()"
  20. value="Restore column size" />
  21.  
  22. </body>
  23. </html>