JavaScript 参考手册
Column span 属性
返回<col>元素横跨的列数(即span的值)
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <style> table, th, td { border: 1px solid black; } </style> </head> <body> <table> <colgroup> <col id="myCol" span="2" style="background-color:red"> <col style="background-color:yellow"> </colgroup> <tr> <th>ISBN</th> <th>Title</th> <th>Price</th> </tr> <tr> <td>3476896</td> <td>My first HTML</td> <td>$53</td> </tr> <tr> <td>5869207</td> <td>My first CSS</td> <td>$49</td> </tr> </table> <p>点击按钮返回列中span属性的值。</p> <p id="demo"></p> <button onclick="myFunction()">点我</button> <script> function myFunction() { var x = document.getElementById("myCol").span; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
运行结果:
点击运行 »