【问题标题】:Broken Nested Table损坏的嵌套表
【发布时间】:2014-01-13 16:59:00
【问题描述】:

我有 mysql 隐藏的嵌套表。单击黄色箭头时,嵌套表显示/隐藏。问题是我的表格行坏了。

就像上图一样,表格的另一行已损坏。这有什么问题?

    <?php
        echo'<table id="tfhover" cellspacing="0" class="tablesorter">
            <thead>
            <tr>
            <th style="display:none;"></th>
            </tr>
            </thead>';
            echo'<tbody>';
        $i=1;   
    while($row = $result->fetch_assoc()){
        echo'<tr>
                <td align="center" id="none">';
                if (empty($row['qtysum'])){
                echo '<a href="javascript:void(0)"></a></td>';
                } else {
                echo '<a onclick="toggleTable(this);" data-counter="'.$rowid.'" href="#"><img src="images/arrow_right.png" border="0" width="15" height="15" title="Show List of '.$row["item_name"].'"></a></td>';
                }
                echo'<td>'.$i++.'</td>
                </tr>';

echo'<tr>';
        echo'<table id="loginTable'.$rowid.'" border="1" align="center" style="display:none">
            <thead>
            <tr>
            <th></th>
            </tr>
            </thead>';
            echo'<tbody>';
        $i=1;   
    while($row = $result1->fetch_assoc()){
        echo'<tr>
            <td>'.$i++.'</td>
            </tr>';
           }
    echo "</tbody></table></tr>";
           }
          }
        echo "</tbody></table>";
    ?>

这是我的显示/隐藏表脚本。

<script>
function toggleTable(link) {
     var elem=document.getElementById("loginTable" + link.getAttribute('data-counter'));
     var hide = elem.style.display =="none";
     if (hide) {
        elem.style.display="table";
     } else {
        elem.style.display="none";
     }
     return false;
 }
</script>

如果有&lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;

【问题讨论】:

  • 查看您的页面源代码并发布由 PHP 代码构建并呈现出与您预期不同的 HTML 标记。这会让我们更容易发现问题。

标签: php jquery mysql html-table


【解决方案1】:

在创建子表之前似乎没有打开父 td,并且结束标记也丢失了。

更改的部分使用&lt;!-- --&gt;进行注释

    <?php
        echo'<table id="tfhover" cellspacing="0" class="tablesorter">
            <thead>
            <tr>
            <th style="display:none;"></th>
            </tr>
            </thead>';
            echo'<tbody>';
        $i=1;   
    while($row = $result->fetch_assoc()){
        echo'<tr>
                <td align="center" id="none">';
                if (empty($row['qtysum'])){
                echo '<a href="javascript:void(0)"></a></td>';
                } else {
                echo '<a onclick="toggleTable(this);" data-counter="'.$rowid.'" href="#"><img src="images/arrow_right.png" border="0" width="15" height="15" title="Show List of '.$row["item_name"].'"></a></td>';
                }
                echo'<td>'.$i++.'</td>
                </tr>';

echo'<tr><td>'; <!-- there was no td opened here -->
        echo'<table id="loginTable'.$rowid.'" border="1" align="center" style="display:none">
            <thead>
            <tr>
            <th></th>
            </tr>
            </thead>';
            echo'<tbody>';
        $i=1;   
    while($row = $result1->fetch_assoc()){
        echo'<tr>
            <td>'.$i++.'</td>
            </tr>';
           }
        echo "</tbody></table>";
    <!-- opened tr,td are closed here -->
        echo "</td></tr>"
           }
          }
        echo "</tbody></table>";
    ?>

【讨论】:

  • 我尝试了你的建议。我用您的回答结果的图像更新了我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多