2

我有一个三列的表。我正在使用标签来指定列的宽度。示例代码:

<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>

问题是 col ($("#id1").width()) 的宽度为 IE 和 Chrome 返回 0,它在 FF 中运行良好。如何获得 chrome 和 IE 中 col 的实际宽度?

4

1 回答 1

0

对旧 jQuery 做简单的修改(col 在 Chrome 中没有宽度,但它有第一个具有宽度的单元格)

<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>

在这里-http://jsfiddle.net/YD5mM/2/

于 2012-03-02T10:43:15.907 回答