简单教程
提交运行
代码编辑器:
<style> table,th,td{ border:1px solid black; } </style> <table> <colgroup id="myColgroup"></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>点击按钮设置表格中前两列的颜色为红色</p> <p id="demo"></p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ document.getElementById("myColgroup").span="2"; document.getElementById("myColgroup").style.backgroundColor="red"; } </script>
运行结果: