<col> width returns 0 for IE and Chrome

混江龙づ霸主 提交于 2019-12-11 01:58:52

问题


I have a table with three columns. I am using tag to specify the width of a column. Sample code:

<table width="100%" border="1">
  <colgroup style="background-color:#FF0000;">
  <col width="100px" id="id1"></col>
  <col width="80px" id="id2"></col><col id="id3"></col></colgroup>
  <tbody>
  <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>2489604</td>
    <td>My first CSS</td>
    <td>$47</td>
  </tr>
<tbody>
</table>

The problem is width of col ($("#id1").width()) returns 0 for IE and Chrome and it works fine in FF. How do I get the actual width of col in chrome and IE?


回答1:


Do the simple hack for older jQuery (col don't have width in Chrome, but it have first cell with width )

<table width="100%" border="1">
  <colgroup style="background-color:#FF0000;">
  <col width="100px"></col>
  <col width="80px"></col><col id="id3"></col></colgroup>
  <tbody>
  <tr>
    <th id="id1">ISBN</th>
    <th id="id2">Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
  <tr>
    <td>2489604</td>
    <td>My first CSS</td>
    <td>$47</td>
  </tr>
<tbody>
</table>

here - http://jsfiddle.net/YD5mM/2/



来源:https://stackoverflow.com/questions/9112849/col-width-returns-0-for-ie-and-chrome

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!