【问题标题】:How to get 8 columns in my second tr?如何在我的第二个 tr 中获得 8 列?
【发布时间】:2014-04-13 10:47:49
【问题描述】:

这是我的 html 代码:http://jsfiddle.net/Udxyb/417/

在上面的代码中,我在第一个 tr 中有四列(例如:section1、section2、section3、section4)。但是在我的表的下一个 tr 中,我想要 8 列与第一个 tr 具有相同的宽度(例如:item 111,第 112 项,第 113 项,第 114 项,第 115 项,第 116 项,第 117 项,第 118 项)。

<table id="main_table">
    <thead>
        <tr class="firstline">
            <th>Column1</th>
            <th>Column2</th>
            <th>Column3</th>
            <th>Column4</th>
        </tr>
    </thead>
    <tbody>
        <tr style="width:1002px; background-color:green; color:white">
            <td  colspan="" class="flip"> Section 1 </td>
             <td  colspan="" class="flip"> Section 2 </td>
             <td  colspan="" class="flip"> Section 3 </td>
             <td  colspan="" class="flip"> Section 4 </td>
        </tr>
    </tbody>
    <tbody class="section">
        <tr>
            <td>item 111</td>
            <td>item 112</td>
            <td>item 113</td>
            <td>item 114</td>
            <td>item 115</td>
            <td>item 116</td>
            <td>item 117</td>
            <td>item 118</td>


        </tr>
        <tr>
            <td>item 121</td>
            <td>item 122</td>
            <td>item 123</td>
            <td>item 124</td>
        </tr>
        <tr>
            <td>item 131</td>
            <td>item 132</td>
            <td>item 133</td>
            <td>item 134</td>
        </tr>
    </tbody>
    <tbody>
        <tr style="background-color:green; color:white">
            <td  colspan="" class="flip"> Section 1 </td>
             <td  colspan="" class="flip"> Section 2 </td>
             <td  colspan="" class="flip"> Section 3 </td>             <td  colspan="" class="flip"> Section 4 </td>
        </tr>
    </tbody>
    <tbody class="section">
        <tr>
            <td>item 211</td>
            <td>item 212</td>
            <td>item 213</td>
            <td>item 214</td>
        </tr>
        <tr>
            <td>item 221</td>
            <td>item 222</td>
            <td>item 223</td>
            <td>item 224</td>
        </tr>
        <tr>
            <td>item 231</td>
            <td>item 232</td>
            <td>item 233</td>
            <td>item 234</td>
        </tr>
    </tbody>
    <tbody>
        <tr style="background-color:green; color:white">
             <td  colspan="" class="flip"> Section 1 </td>
             <td  colspan="" class="flip"> Section 2 </td>
             <td  colspan="" class="flip"> Section 3 </td>
             <td  colspan="" class="flip"> Section 4 </td>
        </tr>
    </tbody>
    <tbody class="section">
        <tr>
            <td>item 311</td>
            <td>item 312</td>
            <td>item 313</td>
            <td>item 314</td>
        </tr>
        <tr>
            <td>item 321</td>
            <td>item 322</td>
            <td>item 323</td>
            <td>item 324</td>
        </tr>
        <tr>
            <td>item 331</td>
            <td>item 332</td>
            <td>item 333</td>
            <td>item 334</td>
        </tr>
    </tbody>
</table>

这是我的 jquery 代码:

jQuery(function($) {


    $("#polls").on("click", ".flip", function() {

        $(this)

            .closest('tbody')
            .next('.section')
            .toggle('fast');
    });
});

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    简单:将 4 列中的所有 td 设置为 colspan="2"

    【讨论】:

      【解决方案2】:

      在具有四个单元格的行中的所有单元格上设置colspan="2"

      【讨论】:

      • 该死的,比我快 5 秒 ;)
      • @LinkinTED 非常感谢,但在点击之前和点击之后宽度必须相同,但在上面的更新中宽度是不同的!!
      • 那是因为内容不合适。 Setting the width of the table 修复它。
      【解决方案3】:

      第二行的 TD 数量翻倍;并在每个 TH 上添加 colspan="2" 以说明它必须有 2 列宽度

      <thead>
          <tr class="firstline">
              <th colspan="2">Column1</th>
              <th colspan="2">Column2</th>
              <th colspan="2">Column3</th>
              <th colspan="2">Column4</th>
          </tr>
      </thead>
      <tbody>
          <tr style="width:1002px; background-color:green; color:white">
              <td  class="flip"> Section 1 </td>
               <td  class="flip"> Section 2 </td>
               <td  class="flip"> Section 3 </td>
               <td  class="flip"> Section 4 </td>
               <td  class="flip"> Section 5 </td>
               <td  class="flip"> Section 6 </td>
               <td  class="flip"> Section 7 </td>
               <td  class="flip"> Section 8 </td>
          </tr>
      </tbody>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多