< COL> IE和Chrome的宽度返回0 [英] <col> width returns 0 for IE and Chrome

查看:76
本文介绍了< COL> IE和Chrome的宽度返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

问题是col的宽度($(#id1)。width())返回0对于IE和Chrome,它在FF中工作正常。
如何在chrome和IE中获得col的实际宽度?

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?

推荐答案

对旧的jQuery进行简单的破解(col在Chrome中没有宽度,但它有第一个宽度的单元格)

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>

此处 - http://jsfiddle.net/YD5mM/2/

这篇关于&LT; COL&GT; IE和Chrome的宽度返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆