2

3列のテーブルがあります。タグを使用して列の幅を指定しています。サンプルコード:

<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の簡単なハックを実行します(Chromeでは col に幅はありませんが、 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>

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

于 2012-03-02T10:43:15.907 に答える