为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Table problem with hidden <tr>

more options

Create "<table width='96%' border='1'><tr><th>a</th><th>b</th><th<c</th><th>d</th><th>e</th></tr><tr id='h'><td>x</td><td>y</td><td colspan='3'>z</td></tr></table>", hide id 'h', then unhide it.

After reshow of <tr id='h'>, FireFox no longer does colspan for

"<td>z</td>" putting 'z' under "th>c</th>".
Create "&lt;table width='96%' border='1'&gt;&lt;tr&gt;&lt;th&gt;a&lt;/th&gt;&lt;th&gt;b&lt;/th&gt;&lt;th&lt;c&lt;/th&gt;&lt;th&gt;d&lt;/th&gt;&lt;th&gt;e&lt;/th&gt;&lt;/tr&gt;&lt;tr id='h'&gt;&lt;td&gt;x&lt;/td&gt;&lt;td&gt;y&lt;/td&gt;&lt;td colspan='3'&gt;z&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;", hide id 'h', then unhide it. After reshow of &lt;tr id='h'&gt;, FireFox no longer does colspan for "&lt;td&gt;z&lt;/td&gt;" putting 'z' under "th&gt;c&lt;/th&gt;".

由cor-el于修改

被采纳的解决方案

As I surmised in my first reply, the error in your script is setting display:block on a table row. Try something like this:


<script type="text/javascript"> function Toggle(a){ var obj=document.getElementById(a); obj.style.display=(obj.style.display!='none')?'none':''; } </script>

This is not a new issue...but it's a familiar one for those who usually develop with IE as their primary test browser. E.g., http://forums.mozillazine.org/viewtopic.php?t=493565#p2623372

定位到答案原位置 👍 0

所有回复 (8)

more options

I'll make a guess at the problem. If you are setting a table row to display:none and then back to display:block, this can create problems in Firefox. Technically, you should set it to display:table-row. However, that causes problems in older versions of IE. For best results, try:


your_tr.style.display = "";

In other words, clear the value of the display property so that Firefox reverts to the default value.

If I guessed wrong, could you link to a page that demonstrates the problem? It could be your real page or a simple test case made up for demonstration. (t's hard to get a deep understanding here because this board isn't friendly to posting HTML.)

more options

FireFox displays the table correctly until it is hidden (with JavaScript). When it is reshown is when the error occurs. It works correctly in IE9.

more options

Happy to help, but need to see the HTML and JavaScript working together. In your original question, you said you were hiding the element with the id="h" which is the tr element, not the entire table. Details are critical here!

more options

I will create a test page.

more options

There is now a test page at www.mybfl.com/test.php. Turns out it is not the colspan being ignored, it is everything about the table spacing. Seamonkey screws it up also. IE9 gets it right.

more options

选择的解决方案

As I surmised in my first reply, the error in your script is setting display:block on a table row. Try something like this:


<script type="text/javascript"> function Toggle(a){ var obj=document.getElementById(a); obj.style.display=(obj.style.display!='none')?'none':''; } </script>

This is not a new issue...but it's a familiar one for those who usually develop with IE as their primary test browser. E.g., http://forums.mozillazine.org/viewtopic.php?t=493565#p2623372

more options

Thanks. I did not realize FireFox did not handle 'block' for a display mode.

more options

Block works fine for most elements that you want to behave like a block (e.g., to make an img behave like a div rather than a span), but applying it to table rows and table cells causes them to no longer behave like table rows and table cells.